Tkinter text making the button move to sides - python

I am trying to create a TicTacToe game in Tkinter and I am trying to put a label under the buttons of the board but when I am put the label under the buttons the buttons are moving to the sides.
how can I fix it?
this is my code:
from tkinter import *
from tkinter import messagebox
root = Tk()
root.title('TicTacToe')
# X starts
clicked = True
count = 0
#button clicked function
def b_click(b):
global clicked
global count
if b["text"] == " " and clicked == True:
b["text"] = "X"
clicked = False
count += 1
elif b["text"] == " " and clicked == False:
b["text"] = "O"
clicked = True
count += 1
else:
messages["text"] = "you cant do that"
#build the buttons
b1 = Button(root, text=" ", font =("Helvetica", 20), height=3, width=6, bg="SystemButtonFace", command= lambda:b_click(b1))
b2 = Button(root, text=" ", font =("Helvetica", 20), height=3, width=6, bg="SystemButtonFace", command= lambda:b_click(b2))
b3 = Button(root, text=" ", font =("Helvetica", 20), height=3, width=6, bg="SystemButtonFace", command= lambda:b_click(b3))
b4 = Button(root, text=" ", font =("Helvetica", 20), height=3, width=6, bg="SystemButtonFace", command= lambda:b_click(b4))
b5 = Button(root, text=" ", font =("Helvetica", 20), height=3, width=6, bg="SystemButtonFace", command= lambda:b_click(b5))
b6 = Button(root, text=" ", font =("Helvetica", 20), height=3, width=6, bg="SystemButtonFace", command= lambda:b_click(b6))
b7 = Button(root, text=" ", font =("Helvetica", 20), height=3, width=6, bg="SystemButtonFace", command= lambda:b_click(b7))
b8 = Button(root, text=" ", font =("Helvetica", 20), height=3, width=6, bg="SystemButtonFace", command= lambda:b_click(b8))
b9 = Button(root, text=" ", font =("Helvetica", 20), height=3, width=6, bg="SystemButtonFace", command= lambda:b_click(b9))
messages = Label(root, text="", font =("Helvetica", 20), height=1, width=15, relief="sunken")
space = Label(root, text="", font =("Helvetica",))
#display the buttons
b1.grid(row=0, column=0)
b2.grid(row=0, column=1)
b3.grid(row=0, column=2)
b4.grid(row=1, column=0)
b5.grid(row=1, column=1)
b6.grid(row=1, column=2)
b7.grid(row=2, column=0)
b8.grid(row=2, column=1)
b9.grid(row=2, column=2)
space.grid(row=3, column=0)
messages.grid(row=4, column=1)
root.mainloop()

When you try to add the label under the buttons, if you don't specify the columnspan the label will take the whole cell, so what happened is that the label is wider than the buttons, and since it took all the cell the buttons went to the sides, so if you put it like this:
...
space.grid(row=3, column=0)
messages.grid(row=4, column=0, columnspan=3)
root.mainloop()
you are telling tkinter that your label is taking the three columns, and so it does not move the buttons anymore. Here's the result:

Related

image "pyimage1" doesn't exist

I am coding a automation interface using tkinter and i have to import a second py file from the first by press of a button, the importing works but i am faced with an error that says "image "pyimage1" doesn't exist", here is the code for the main interface"
import tkinter as tk1
window=tk1.Tk()
window.wm_title("Main Interface")
def Function():
import What
#main
Canvas= tk1.Canvas(window, height=1000, width=1000)
Canvas.grid(row=30, column=20)
Label1=tk1.Label(Canvas, text="WELCOME TO DIGITAL AUTOMATION", bg="#eddea8", font="Verdana 34", relief="solid", borderwidth=5)
Label1.grid(row=0, column=1)
Label1=tk1.Label(Canvas, text="What do you want to perform ? ", bg="#eddea8", font="Verdana 18", relief="solid", borderwidth=5)
Label1.grid(row=1, column=1)
Label2=tk1.Label(Canvas, text="Schedule A message ?", bg="#33CCFF", font="Verdana 12")
Label2.grid(row=2, column=0)
Button1=tk1.Button(Canvas, bg="#59cced", text="Press Here", font="Verdana 18", command=Function)
Button1.grid(row=3, column=0)
window.mainloop()
----------and here is the code for the whatsapp automation---------------------------------
from tkinter import *
import pywhatkit
#import pkg_resources.py2_warn
root = Tk()
root.wm_iconbitmap("icon/default.ico")
root.wm_title("Mscheduler")
bg = PhotoImage(file = "1187248.png")
#root.geometry("965x250")
#Function
def Function():
n=Entry1.get()
m=Entry2.get()
L=Entry3.get()
I=Entry4.get()
y="+91"
pywhatkit.sendwhatmsg(y+n,str(m),int(L),int(I))
Entry1.delete(0,END)
Entry2.delete(0,END)
Entry3.delete(0,END)
Entry4.delete(0,END)
#def delete():
#Entry1.delete(0,END)
#mainscreen
Canvas = Canvas(root, height=1000, width=1000)
Canvas.grid(row=30, column=20)
Canvas.create_image( 0, 0, image = bg, anchor = "nw")
Label1 = Label(Canvas, text="Mscheduler",bg='#99e6ff',font="Verdana 34", relief="solid", borderwidth=5)
Label1.grid(row=0,column=1)
Label2= Label(Canvas, bg="#A9ECFF", text="Phone no:",font="verdana 18")
Label2.grid(row=2 , column=0)
#Canvas.create_text(105, 115, text="Phone No.:",font="verdana 18")
#Canvas.create_text.grid(row=2 , column=0)
Entry1=Entry(Canvas,bg="#ffe6b3",font="verdana 18", relief="ridge", borderwidth=3)
Entry1.grid(row=2, column=1)
Label3= Label(Canvas,bg="#A9ECFF", text=" Message:",font="verdana 18")
Label3.grid(row=3 , column=0)
#Canvas.create_text(115, 170, text="Message:",font="verdana 18")
Entry2=Entry(Canvas,bg="#ffe6b3",font="verdana 18", relief="ridge", borderwidth=3)
Entry2.grid(row=3, column=1)
Label4= Label(Canvas,bg="#A9ECFF", text=" Hour:",font="verdana 18")
Label4.grid(row=4 , column=0)
#Canvas.create_text(135, 225, text=" Hour:",font="verdana 18")
Entry3=Entry(Canvas,bg="#ffe6b3",font="verdana 18", relief="ridge", borderwidth=3)
Entry3.grid(row=4, column=1)
Label5= Label(Canvas, bg="#A9ECFF", text=" Minutes:",font="verdana 18")
Label5.grid(row=5 , column=0)
#Canvas.create_text(135,225 text="Minutes:", font="verdana 18")
#Canvas.create_text(200, 350, text="Phone No.:",font="verdana 18")
Entry4=Entry(Canvas,bg="#ffe6b3",font="verdana 18", relief="ridge", borderwidth=3)
Entry4.grid(row=5, column=1)
Button1=Button(Canvas, bg="#d1d1e0", text="send --->", font="verdana 18", borderwidth=3, command=Function)
Button1.grid(row=7, column=2)
#Button1=Button(Canvas, bg="#d1d1e0", text="delete", font="verdana 18", borderwidth=5, command=delete)
#Button1.grid(row=7, column=1)
root.mainloop()
i tried using tk.Toplevel and all but it doesnt seem to work, please help
This task does not require the use of two instances of Tk. You should read about splitting a program into modules and about naming variables in python. The sample program consists of two files main.py and whatsappauto.py. I didn't import some libraries to make it easier to show how to work with two modules.
main.py
import tkinter as tk
from functools import partial
import whatsappauto # Importing a second file
window=tk.Tk()
window.wm_title("Main Interface")
def Function(window):
# Calling a function from another file
whatsappauto.top_level(window)
#main
canvas= tk.Canvas(window, height=1000, width=1000)
canvas.grid(row=30, column=20)
Label1=tk.Label(canvas, text="WELCOME TO DIGITAL AUTOMATION", bg="#eddea8", font="Verdana 34", relief="solid", borderwidth=5)
Label1.grid(row=0, column=1)
Label1=tk.Label(canvas, text="What do you want to perform ? ", bg="#eddea8", font="Verdana 18", relief="solid", borderwidth=5)
Label1.grid(row=1, column=1)
Label2=tk.Label(canvas, text="Schedule A message ?", bg="#33CCFF", font="Verdana 12")
Label2.grid(row=2, column=0)
Button1=tk.Button(canvas, bg="#59cced", text="Press Here", font="Verdana 18", command=partial(Function, window))
Button1.grid(row=3, column=0)
window.mainloop()
whatsappauto.py
import tkinter as tk
from functools import partial
def Function(Entry1, Entry2, Entry3, Entry4):
n = Entry1.get()
m = Entry2.get()
L = Entry3.get()
I = Entry4.get()
y = "+91"
# pywhatkit.sendwhatmsg(y + n, str(m), int(L), int(I))
Entry1.delete(0, tk.END)
Entry2.delete(0, tk.END)
Entry3.delete(0, tk.END)
Entry4.delete(0, tk.END)
def top_level(root):
global canvas_bg
newWindow1 = tk.Toplevel(root)
newWindow1.wm_iconbitmap("icon/default.ico")
newWindow1.wm_title("Mscheduler")
canvas = tk.Canvas(newWindow1)
canvas.pack()
canvas_bg = tk.PhotoImage(file='1187248.png')
canvas.create_image(0, 0, image=canvas_bg, anchor="nw")
Label1 = tk.Label(canvas, text="Mscheduler", bg='#99e6ff', font="Verdana 34", relief="solid", borderwidth=5)
Label1.grid(row=0, column=1)
Label2 = tk.Label(canvas, bg="#A9ECFF", text="Phone no:", font="verdana 18")
Label2.grid(row=2, column=0)
Entry1 = tk.Entry(canvas, bg="#ffe6b3", font="verdana 18", relief="ridge", borderwidth=3)
Entry1.grid(row=2, column=1)
Label3 = tk.Label(canvas, bg="#A9ECFF", text=" Message:", font="verdana 18")
Label3.grid(row=3, column=0)
# Canvas.create_text(115, 170, text="Message:",font="verdana 18")
Entry2 = tk.Entry(canvas, bg="#ffe6b3", font="verdana 18", relief="ridge", borderwidth=3)
Entry2.grid(row=3, column=1)
Label4 = tk.Label(canvas, bg="#A9ECFF", text=" Hour:", font="verdana 18")
Label4.grid(row=4, column=0)
Entry3 = tk.Entry(canvas, bg="#ffe6b3", font="verdana 18", relief="ridge", borderwidth=3)
Entry3.grid(row=4, column=1)
Label5 = tk.Label(canvas, bg="#A9ECFF", text=" Minutes:", font="verdana 18")
Label5.grid(row=5, column=0)
Entry4 = tk.Entry(canvas, bg="#ffe6b3", font="verdana 18", relief="ridge", borderwidth=3)
Entry4.grid(row=5, column=1)
Button1 = tk.Button(canvas, bg="#d1d1e0", text="send --->", font="verdana 18",
borderwidth=3, command=partial(Function, Entry1, Entry2, Entry3, Entry4))
Button1.grid(row=7, column=2)

Python TKinter Mac: Buttons layout strangely & click don't work

Python TKinter Mac: Buttons layout strangely and when a button is clicked it looks the same (as if it hadn't been clicked) however I didn't check to see if the button worked.
and the space is a textbook
the Mac version is: a 2017 iMac running Monterey 12.4
import tkinter as tk
window = tk.Tk()
window.geometry("500x500")
window.title("Stock Watchlist & Logger")
label = tk.Label(window, text="Tester", font=('Ariel', 18))
label.pack(padx=20, pady=20)
textbox = tk.Text(window, height=3, font=('Ariel', 16))
textbox.pack(padx=10, pady=10)
numbuttframe = tk.Frame(window)
numbuttframe.columnconfigure(0, weight=1)
yesnobuttframe = tk.Frame(window)
yesnobuttframe.columnconfigure(1, weight=1)
button1 = tk.Button(numbuttframe, text="1", font=('Arial', 18))
button1.grid(row=0, column=0, sticky=tk.W+tk.E)
button2 = tk.Button(numbuttframe, text="2", font=('Arial', 18))
button2.grid(row=0, column=1, sticky=tk.W+tk.E)
button3 = tk.Button(numbuttframe, text="3", font=('Arial', 18))
button3.grid(row=0, column=2, sticky=tk.W+tk.E)
button4 = tk.Button(numbuttframe, text="4", font=('Arial', 18))
button4.grid(row=0, column=3, sticky=tk.W+tk.E)
button5 = tk.Button(numbuttframe, text="5", font=('Arial', 18))
button5.grid(row=0, column=4, sticky=tk.W+tk.E)
button6 = tk.Button(numbuttframe, text="6", font=('Arial', 18))
button6.grid(row=0, column=5, sticky=tk.W+tk.E)
yesbutton = tk.Button(yesnobuttframe, text="Yes", font=('Arial', 18))
yesbutton.grid(row=0, column=0, sticky=tk.W+tk.E)
nobutton = tk.Button(yesnobuttframe, text="No", font=('Arial', 18))
nobutton.grid(row=0, column=1, sticky=tk.W+tk.E)
numbuttframe.pack(fill='x')
yesnobuttframe.pack(fill='x')
if button1:
print("CELEBRATE!")
window.mainloop()
You set the weight to two cells weight=1 , so they expanded, since the rest have a default weight of 0. Since I don’t see your grid - the buttons are placed in frames one after the other, suggest using the pack method. And shortened your code a bit. The buttons won't work yet, because they don't have a command = call. Complex variable names in Python are usually written with an underscore.
import tkinter as tk
FONT = ('Ariel', 18)
window = tk.Tk()
window.geometry("500x500")
window.title("Stock Watchlist & Logger")
lbl = tk.Label(window, text="Tester", font=FONT)
lbl.pack(padx=20, pady=20)
text_box = tk.Text(window, height=3, font=('Ariel', 16))
text_box.pack(padx=10, pady=10)
num_btn = tk.Frame(window)
yes_no_btn = tk.Frame(window)
num_btn.pack(fill='x')
yes_no_btn.pack(fill='x')
buttons = []
for i in range(1, 7):
btn = tk.Button(num_btn, text=f"{i}", font=FONT)
btn.pack(side="left", fill='x', expand=True)
buttons.append(btn)
yes_btn = tk.Button(yes_no_btn, text="Yes", font=FONT)
yes_btn.pack(side="left", fill='x', expand=True)
no_btn = tk.Button(yes_no_btn, text="No", font=FONT)
no_btn.pack(side="left", fill='x', expand=True)
window.mainloop()

I need help trying to create the frontend interface of a gui via tkinter

The buttons, for some reason, seem to be positioned wrong. I checked my code, and it's written to have the correct positioning, but it for some reason is showing all of the buttons except for the "View All" buttons to be too low. The buttons are supposed to be right above each other. Could ya'll help and let me know what the problem is?
from tkinter import *
window = Tk()
#Labels
l1 = Label(window, text="Title")
l1.grid(row=0, column=0)
l2 = Label(window, text="Author")
l2.grid(row=0, column=2)
l3 = Label(window, text="Year")
l3.grid(row=1, column=0)
l4 = Label(window, text="ISBN")
l4 .grid(row=1, column=2)
#Entry boxes
title_text=StringVar()
e1 = Entry(window, textvariable=title_text)
e1.grid(row=0, column=1)
author_text=StringVar()
e2 = Entry(window, textvariable=author_text)
e2.grid(row=0, column=3)
year_text=StringVar()
e3 = Entry(window, textvariable=year_text)
e3.grid(row=1, column=1)
isbn_text=StringVar()
e4 = Entry(window, textvariable=isbn_text)
e4.grid(row=1, column=3)
#listbox
ls1 = Listbox(window, height=6,width=35)
ls1.grid(row=2, column=0)
#Scrollbar
scr1 = Scrollbar(window)
scr1.grid(row=2, column=2, rowspan=6)
#Making the scrolbar scroll down the listbox
ls1.configure(yscrollcommand=scr1.set)
scr1.configure(command=ls1.yview)
#Buttons and stuff
b1 = Button(window, text="View all", width=12)
b1.grid(row=2, column=3)
b2 = Button(window, text="Search Entry", width=12)
b2.grid(row=3, column=3)
b3 = Button(window, text="Add Entry", width=12)
b3.grid(row=4, column=3)
b4 = Button(window, text="Update Selected", width=12)
b4.grid(row=5, column=3)
b5 = Button(window, text="Delete Selected", width=12)
b5.grid(row=6, column=3)
b6 = Button(window, text="Exit", width=12)
b6.grid(row=7, column=3)
window.mainloop()

How can I change the button of a calculator app in Tkinter?

I have been doing a python app for a calculator with Tkinter. I want to know how access the buttons properties such as their size, height, width and color by the use of strings. So far I have been able to change the background of the lines behind the buttons to red by using style.configure("TButton", background='red',
font="Serif 15",
padding=10 ).
How do I change the buttons themselves? If anyone could help me I would greatly appreciate it.
from tkinter import *
from tkinter.ttk import *
from tkinter import ttk
class Calculator:
calc_value = 0.0
div_trigger = False
mult_trigger = False
add_trigger = False
sub_trigger = False
def __init__(self,root):
self.entry_value = StringVar(root,value="")
root.title("Calculator")
root.geometry("600x500")
root.resizable(width=True, height=True)
style = ttk.Style()
style.configure(self, background='red')
style.configure("TButton", #background='red',
font="Serif 15",
padding=10 )
style.configure("TEntry",
font="Serif 15",
padding=10 )
self.number_entry = ttk.Entry(root,
textvariable=self.entry_value,width=50)
self.number_entry.grid(row=0, columnspan=4)
#-------1st row---------
self.button7 = ttk.Button(root, text="7",
command=lambda: self.button_press('7')).grid(row=1, column=0)
self.button8 = ttk.Button(root, text="8",
command=lambda: self.button_press('8')).grid(row=1, column=1)
self.button9 = ttk.Button(root, text="9",
command=lambda: self.button_press('9')).grid(row=1, column=2)
self.button_div = ttk.Button(root, text="/",
command=lambda: self.button_press('/')).grid(row=1, column=3)
#-------2nd row---------
self.button4 = ttk.Button(root, text="4",
command=lambda: self.button_press('4')).grid(row=2, column=0)
self.button5 = ttk.Button(root, text="5",
command=lambda: self.button_press('5')).grid(row=2, column=1)
self.button6 = ttk.Button(root, text="6",
command=lambda: self.button_press('6')).grid(row=2, column=2)
self.button_mult = ttk.Button(root, text="*",
command=lambda: self.button_press('*')).grid(row=2, column=3)
#-------3rd row---------
self.button1 = ttk.Button(root, text="1",
command=lambda: self.button_press('1')).grid(row=4, column=0)
self.button2 = ttk.Button(root, text="2",
command=lambda: self.button_press('2')).grid(row=4, column=1)
self.button3 = ttk.Button(root, text="3",
command=lambda: self.button_press('3')).grid(row=4, column=2)
self.button_add = ttk.Button(root, text="+",
command=lambda: self.button_press('+')).grid(row=4, column=3)
#-------4th row---------
self.button_clear = ttk.Button(root, text="AC",
command=lambda: self.button_press('AC')).grid(row=5, column=0)
self.button0 = ttk.Button(root, text="0",
command=lambda: self.button_press('0')).grid(row=5, column=1)
self.button_equal = ttk.Button(root, text="=",
command=lambda: self.button_press('=')).grid(row=5, column=2)
self.button_sub = ttk.Button(root, text="-",
command=lambda: self.button_press('-')).grid(row=5, column=3)
root = Tk()
calc = Calculator(root)
root.mainloop()
#button1 = Button(topframe,padx=16, pady=16, bd=8, text="1", fg="black", bg = random.choice(colors))
Here are documentatiopn about that.
http://effbot.org/tkinterbook/button.htm
If you want to change a botton size you can use.
button1.config(height = 100, width = 100)

Tkinter Calculator Python 3.4.2

I am trying to create a program in python 3.4.2 using tkinter. I hope to create a GUI calculator. So far i've been able to code out the buttons and layout (interface) of the program. The only thing that i need help with is the actions that the buttons perform. For example, i need a way to enter the value of the button pressed into my entry bar at the top of the calculator. (e,g: I press button 7 and 7 pops up into my entry bar). I need help coding that because i don't know how. So far my only working button on screen is the clear (ce) button as it clears the whole entry bar in my GUI. Can someone please take a look at my code below to help me establish a way to get this calculator working. (P.S i'm not no genius at tkinter, so basically try to explain it to me as you would to to a 10 year old LOOL).
Summary:
Connect my buttons to my entry bar.
My code:
#Project Name : Calculator ++
#Version : 1.7.2
#Written by : Pamal Mangat.
#Start Date : Monday, July 7th, 2015.
import sys
from tkinter import *
from PIL import Image, ImageTk
def clear():
txtDisplay.delete(0,END);
return;
#Parent Window.
root = Tk();
root.title('Calculator ++ [1.7.2]');
root.geometry('350x450');
#Main entry.
num1 = StringVar();
txtDisplay = Entry(root, textvariable = num1, relief=RIDGE, bd = 10, width=33, insertwidth = 1, font = 40);
txtDisplay.place(x=15, y=10);
txtDisplay.focus();
#Buttons:
zeroButton = Button(root, text='0', width=20, height=3, bg='LightBlue', fg='red').place(x=17,y=382);
oneButton = Button(root, text='1', width=8, height=3, bg='LightBlue', fg='red').place(x=17, y=302);
twoButton = Button(root, text='2', width=8, height=3, bg='LightBlue', fg='red').place(x=100, y=302);
threeButton = Button(root, text='3', width=8, height=3, bg='LightBlue', fg='red').place(x=182, y=302);
fourButton = Button(root, text='4', width=8, height=3, bg='LightBlue', fg='red').place(x=17, y=222);
fiveButton = Button(root, text='5', width=8, height=3, bg='LightBlue', fg='red').place(x=100, y=222);
sixButton = Button(root, text='6', width=8, height=3, bg='LightBlue', fg='red').place(x=182, y=222);
sevenButton = Button(root, text='7', width=8, height=3, bg='LightBlue', fg='red').place(x=17, y=142);
eightButton = Button(root, text='8', width=8, height=3, bg='LightBlue', fg='red').place(x=100, y=142);
ninthButton = Button(root, text='9', width=8, height=3, bg='LightBlue', fg='red').place(x=182, y=142);
decimalButton = Button(root, text='.', width=8, height=3, bg='powder blue').place(x=182, y=382);
equalButton = Button(root, text='=', width=8, height=8, bg='Lightgreen').place(x=264, y=307);
plusButton = Button(root, text='+', width=8, height=3, bg='gray').place(x=264, y=222);
minusButton = Button(root, text='-', width=8, height=3, bg='gray').place(x=264, y=142);
multiplyButton = Button(root, text='x', width=8, height=3, bg='gray').place(x=264, y=66);
divideButton = Button(root, text='÷', width=8, height=3, bg='gray').place(x=182, y=66);
clearButton = Button(root, text='Clear (CE)', width=20, height=3, command = clear, bg='Orange').place(x=17, y=66);
#Locks the parent windows size.
root.maxsize(350,450);
root.minsize(350,450);
#Parent window's background color:
root.configure(background = 'black');
root.mainloop();
Below is an image of what my code executes and looks like once it's runned. The only issue is that it's just a bunch of pushable buttons with no use; except for clear(ce) which i happened to get running. The other buttons need meaning and a function, because i really want to get this program up and running.
As ppl wrote in the comments, you need a function that will respond to button pressed and will update the Entry widget. I modified the code, to show how it can be done:
import sys
from tkinter import *
from PIL import Image, ImageTk
def clear():
txtDisplay.delete(0,END);
return;
#Parent Window.
root = Tk();
root.title('Calculator ++ [1.7.2]');
root.geometry('350x450');
#Main entry.
num1 = StringVar();
txtDisplay = Entry(root, textvariable = num1, relief=RIDGE, bd = 10, width=33, insertwidth = 1, font = 40);
txtDisplay.place(x=15, y=10);
txtDisplay.focus();
def update_entry(v):
current_value = num1.get()
num1.set(current_value + v)
#Buttons:
zeroButton = Button(root, text='0', width=20, height=3, bg='LightBlue', fg='red', command = lambda: update_entry('0')).place(x=17,y=382);
oneButton = Button(root, text='1', width=8, height=3, bg='LightBlue', fg='red', command = lambda: update_entry('1')).place(x=17, y=302);
twoButton = Button(root, text='2', width=8, height=3, bg='LightBlue', fg='red').place(x=100, y=302);
threeButton = Button(root, text='3', width=8, height=3, bg='LightBlue', fg='red').place(x=182, y=302);
fourButton = Button(root, text='4', width=8, height=3, bg='LightBlue', fg='red').place(x=17, y=222);
fiveButton = Button(root, text='5', width=8, height=3, bg='LightBlue', fg='red').place(x=100, y=222);
sixButton = Button(root, text='6', width=8, height=3, bg='LightBlue', fg='red').place(x=182, y=222);
sevenButton = Button(root, text='7', width=8, height=3, bg='LightBlue', fg='red').place(x=17, y=142);
eightButton = Button(root, text='8', width=8, height=3, bg='LightBlue', fg='red').place(x=100, y=142);
ninthButton = Button(root, text='9', width=8, height=3, bg='LightBlue', fg='red').place(x=182, y=142);
decimalButton = Button(root, text='.', width=8, height=3, bg='powder blue').place(x=182, y=382);
equalButton = Button(root, text='=', width=8, height=8, bg='Lightgreen').place(x=264, y=307);
plusButton = Button(root, text='+', width=8, height=3, bg='gray', command = lambda: update_entry('+')).place(x=264, y=222);
minusButton = Button(root, text='-', width=8, height=3, bg='gray').place(x=264, y=142);
multiplyButton = Button(root, text='x', width=8, height=3, bg='gray').place(x=264, y=66);
divideButton = Button(root, text='÷', width=8, height=3, bg='gray').place(x=182, y=66);
clearButton = Button(root, text='Clear (CE)', width=20, height=3, command = clear, bg='Orange').place(x=17, y=66);
#Locks the parent windows size.
root.maxsize(350,450);
root.minsize(350,450);
#Parent window's background color:
root.configure(background = 'black');
root.mainloop();
I added update_entry function that updates the Entry text variable. Also added lambdas to buttons 0 and 1 and + for an instration of use. Other buttons are not done. Also dont use place (or grid) in one line as you have now as all your Button variables will be None.

Categories

Resources