How to remove 2 buttons by pressing one? - python

I want to remove the buttons "play" and "help" by pressing just on button "play". How can I do that? I need that the button "play" destroy himself and in addition destroy the button "help"
This is my code:
from tkinter import *
import tkinter.messagebox
from random import *
window = Tk()
window.title("Simon")
window.geometry("300x200")
label = Label(window, text="Simon Game!", font=("Ariel", 80),
bg="CadetBlue3")
label.pack()
window.configure(bg="CadetBlue3")
def destroy(button):
def inner():
button.destroy()
return inner
def click_help_button():
tkinter.messagebox.showinfo("Instructions", "The device
creates a series of tones and lights and requires a user to
repeat the sequence. If the user succeeds, the series becomes
progressively longer and more complex. Once the user fails, the
game is over")
help_btn = Button(window, width=12, height=2, text="Help",
bg="grey",font=("Ariel", 18), command=click_help_button)
help_btn.pack(side='bottom')
help_btn.place(x=800, y=150)
start_btn = Button(window, width=12, height=2, text="Play",
bg="grey", font=("Ariel", 18), command=destroy(help_btn))
start_btn.pack(pady=10)
start_btn.place(x=525, y=150)
start_btn.config(command=destroy(start_btn))
red_btn = Button(window, width=35, height=15, bg='red')
red_btn.place(x=495, y=270)
green_btn = Button(window, width=35, height=15, bg='green')
green_btn.place(x=750, y=270)
blue_btn = Button(window, width=35, height=15, bg='blue')
blue_btn.place(x=495, y=495)
yellow_btn = Button(window, width=35, height=15, bg='yellow')
yellow_btn.place(x=750, y=495)
window.mainloop()
Thanks to those who help!

I would make a click_play_button function
def click_play_button():
start_btn.destroy()
help_btn.destroy()
And call on it when pressing the play button
start_btn = Button(window, width=12, height=2, text="Play",
bg="grey", font=("Ariel", 18), command=click_play_button)
start_btn.pack(pady=10)
start_btn.place(x=525, y=150)
Below also worked...
def destroy(button):
button.destroy()
def click_help_button():
tkinter.messagebox.showinfo("Instructions", "The device")
help_btn = Button(window, width=12, height=2, text="Help",
bg="grey", font=("Ariel", 18), command=click_help_button)
help_btn.pack(side='bottom')
help_btn.place(x=800, y=150)
start_btn = Button(window, width=12, height=2, text="Play",
bg="grey", font=("Ariel", 18), command=lambda: [destroy(help_btn), destroy(start_btn)])
start_btn.pack(pady=10)
start_btn.place(x=525, y=150)
red_btn = Button(window, width=35, height=15, bg='red')
red_btn.place(x=495, y=270)
green_btn = Button(window, width=35, height=15, bg='green')
green_btn.place(x=750, y=270)
blue_btn = Button(window, width=35, height=15, bg='blue')
blue_btn.place(x=495, y=495)
yellow_btn = Button(window, width=35, height=15, bg='yellow')
yellow_btn.place(x=750, y=495)
window.mainloop()

Related

it seems like i can't open a frame in python

i want to open the menu_frame by clicking the login_button but the frame won't come up and there are no error messages showing up. its my first time and im so lost
ive tried to google how to fix this problem but from what ive read, it seems to me that there are no errors or any reason for this code to not function properly. please help :(
from tkinter import *
window = Tk()
window.title("EL TALLO")
window.geometry("700x490")
window.config(background="#FFF8E5")
#회원가입
def register_frame():
register_frame = Frame(
window,
bd=2,
bg='#FFF8E5',
relief=SOLID,
padx=10,
pady=10
)
Label(
register_frame,
text="ID입력",
bg='#CCCCCC',
).grid(row=0, column=0, sticky=W, pady=10)
Label(
register_frame,
text="비밀번호 입력",
bg='#CCCCCC',
).grid(row=5, column=0, sticky=W, pady=10)
newlyset_id = Entry(
register_frame
)
newlyset_pw = Entry(
register_frame,
show='*'
)
register_btn = Button(
register_frame,
width=15,
text='회원가입',
relief=SOLID,
cursor='hand2',
command=register_frame.destroy
)
newlyset_id.grid(row=0, column=1, pady=10, padx=20)
newlyset_pw.grid(row=5, column=1, pady=10, padx=20)
register_btn.grid(row=7, column=1, pady=10, padx=20)
register_frame.pack()
register_frame.place(x=220, y=150)
def new_id(): #new_id에 newlyset_id에 입력한 값을 저장
new_id = newlyset_id.get()
def new_pw(): #new_pw에 newlyset_pw에 입력한 값을 저장
new_pw = newlyset_pw.get()
#메뉴화면
def menu_frame():
menu_frame = Frame(
window,
bd=2,
bg='#FFF8E5',
relief=SOLID,
padx=10,
pady=10
)
label1 = Label(menu_frame, text = "EL TALLO", bg="lightgreen",width=10, height=1, font=(15))
label1.pack()
btn1 = Button(menu_frame, text = "play game", bg="gray", width=15, height=1)
btn1.pack()
btn2 = Button(menu_frame, text = "How to play", bg="gray", width=15, height=1)
btn2.pack()
btn3 = Button(menu_frame, text = "Settings", bg="gray", width=15, height=1)
btn3.pack()
def btncmd():
print("게임이 종료되었습니다")
btn4 = Button(menu_frame, text = "END GAME", command=btncmd, bg="lightgreen", width=15, height=1)
btn4.pack()
label1.place(x=50, y=50)
btn1.place(x=50, y=100)
btn2.place(x=50, y=150)
btn3.place(x=50, y=200)
btn4.place(x=50, y=250)
#로그인
Label(
window,
text="아이디 입력",
bg='#CCCCCC',
).place(x=230, y=170)
id_tf = Entry(
window,
).place(x=330, y=170)
def id(): #id에 id_tf에 입력한 값을 저장
id = id_tf.get()
Label(
window,
text="비밀번호 입력",
bg='#CCCCCC',
).place(x=230, y=220)
pw_tf = Entry(
window,
).place(x=330, y=220)
def pw(): #pw에 pw_tf에 입력한 값을 저장
pw = pw_tf.get()
#회원가입 버튼
registerbutton = Button(
window,
width=15,
text="회원가입",
bg="#CCCCCC",
cursor='hand2',
command=register_frame
)
registerbutton.place(x=360, y=270)
#로그인 버튼
loginbutton = Button(
window,
width=15,
text="로그인",
bg="#CCCCCC",
cursor='hand2',
command=menu_frame
)
loginbutton.place(x=230, y=270)
window.mainloop()
You didn't pack the menu_frame and the indentation of def btncmd() was wrong.
That is:
btn3 = Button(menu_frame, text = "Settings", bg="gray", width=15, height=1)
btn3.pack()
menu_frame.pack()
def btncmd():
print("게임이 종료되었습니다")

Show the label among the selections, depending on the radio-button clicked in TKinter?

I am having a problem with, only having a single label to show in an instance of clicking the radio button. I want to show that label depending with the radio-button I clicked, I tried reading about pack/grid_forget, but I think I still don't understand it pretty well, or I am just doing it really wrong in my code.
from tkinter import *
root = Tk()
# I squeezed them inside a frame, just for aesthetic reasons.
btn_frame = LabelFrame(root, text='', padx=20, pady=20)
btn_frame.grid(row=0, column=0, columnspan=3, padx=10, pady=10)
# I use button widgets, instead of other widgets.Because I felt buttons are square, and they are easy
to visualize.
red_btn = Button(btn_frame, text='R', padx=40, pady=40)
blue_btn = Button(btn_frame, text='B', padx=40, pady=40)
green_btn = Button(btn_frame, text='G', padx=40, pady=40)
red_btn.grid(row=0, column=0)
blue_btn.grid(row=0, column=1)
green_btn.grid(row=0, column=2)
def rad_btnClick(value):
red_Btn_press_label = Label(root, text='You press R!', padx=40, bg='red')
blu_Btn_press_label = Label(root, text='You press B!', padx=40, bg='blue')
grn_Btn_press_label = Label(root, text='You press G!', padx=40, bg='green')
if value == 1:
red_Btn_press_label.grid(row=2, column=0,)
red_btn = Button(btn_frame, text='r', padx=40, pady=40, bg='red')
red_btn.grid(row=0, column=0)
blu_Btn_press_label.grid_forget()
grn_Btn_press_label.grid_forget()
elif value == 2:
blu_Btn_press_label.grid(row=2, column=1)
blue_btn = Button(btn_frame, text='b', padx=40, pady=40, bg='blue')
blue_btn.grid(row=0, column=1)
red_Btn_press_label.grid_forget()
grn_Btn_press_label.grid_forget()
elif value == 3:
grn_Btn_press_label.grid(row=2, column=2)
green_btn = Button(btn_frame, text='g', padx=40, pady=40, bg='green')
green_btn.grid(row=0, column=2)
red_Btn_press_label.grid_forget()
blu_Btn_press_label.grid_forget()
radiopress = IntVar()
# LABEL, VALUE, COLUMN
RAD_BUTTONS = [('RED BTN', 1, 0),
('BLU BTN', 2, 1),
('GRN BTN', 3, 2)]
for color, value, column in RAD_BUTTONS:
rad_btn = Radiobutton(root, text=color, variable=radiopress, value=value, command= lambda:rad_btnClick(radiopress.get()))
rad_btn.grid(row=1, column=column)
root.mainloop()
So I am new in Python, I've just recently understood the 4/5 core fundamentals in every prog-language.
And now I am trying to learn about GUI with python, with Tkinter. I think my code got a bit longer, for something so simple and small. You can lecture my anyway you want, I just want learn good practices, and work on bad habits I may be doing.
I figured out that I should make my widgets global, and just make an update function to display every time an instance of them is created.
I want to thank Tim Roberts for helping me.
from tkinter import *
root = Tk()
btn_frame = LabelFrame(root, text='', padx=20, pady=20)
btn_frame.grid(row=0, column=0, columnspan=3, padx=10, pady=10)
red_btn = Button(btn_frame, text='R', padx=40, pady=40)
blue_btn = Button(btn_frame, text='B', padx=40, pady=40)
green_btn = Button(btn_frame, text='G', padx=40, pady=40)
red_btn.grid(row=0, column=0)
blue_btn.grid(row=0, column=1)
green_btn.grid(row=0, column=2)
def rad_btnClick(value):
global rad_btn_press_label
global red_btn
global blue_btn
global green_btn
if value == 1:
rad_btn_press_label.grid_forget()
rad_btn_press_label = Label(root, text='You press R!', padx=40, bg='red')
red_btn = Button(btn_frame, text='R', padx=40, pady=40, bg='red')
blue_btn = Button(btn_frame, text='B', padx=40, pady=40)
green_btn = Button(btn_frame, text='G', padx=40, pady=40)
rad_btn_press_label.grid(row=2, column=0)
red_btn.grid(row=0, column=0)
blue_btn.grid(row=0, column=1)
green_btn.grid(row=0, column=2)
elif value == 2:
rad_btn_press_label.grid_forget()
rad_btn_press_label = Label(root, text='You press R!', padx=40, bg='blue')
red_btn = Button(btn_frame, text='R', padx=40, pady=40)
blue_btn = Button(btn_frame, text='B', padx=40, pady=40, bg='blue')
green_btn = Button(btn_frame, text='G', padx=40, pady=40)
rad_btn_press_label.grid(row=2, column=1)
red_btn.grid(row=0, column=0)
blue_btn.grid(row=0, column=1)
green_btn.grid(row=0, column=2)
elif value == 3:
rad_btn_press_label.grid_forget()
rad_btn_press_label = Label(root, text='You press G!', padx=40, bg='green')
red_btn = Button(btn_frame, text='R', padx=40, pady=40)
blue_btn = Button(btn_frame, text='B', padx=40, pady=40)
green_btn = Button(btn_frame, text='G', padx=40, pady=40, bg='green')
rad_btn_press_label.grid(row=2, column=2)
red_btn.grid(row=0, column=0)
blue_btn.grid(row=0, column=1)
green_btn.grid(row=0, column=2)
radiopress = IntVar()
# LABEL, VALUE, ROW, COLUMN
RAD_BUTTONS = [('RED BTN', 1, 1, 0),
('BLU BTN', 2, 1, 1),
('GRN BTN', 3, 1, 2)]
for color, value, row, column in RAD_BUTTONS:
rad_btn = Radiobutton(root, text=color, variable=radiopress, value=value, command=lambda: rad_btnClick(radiopress.get()))
rad_btn.grid(row=row, column=column)
rad_btn_press_label = Label(root, text='You press R!', padx=40,)
rad_btn_press_label.grid(row=2, column=0, )
rad_btn_press_label.grid_forget()
root.mainloop()

How to update Labels in tkinter?

I'm trying to create a program in where you put a word in a box, press add, and this word goes to a list, which is also displayed on the right side. When I press the forward button the first thing on the list is deleted. Problem is I can't get the labels to update when I press the buttons / edit the list.
from tkinter import *
root = Tk()
root.title('Speakers List')
root.minsize(800, 600)
speakers = ['none']
spe = speakers[0]
def add():
if spe == 'none':
speakers.insert(0, [s])
e.delete(0, END)
spe.config(text=speakers[0])
else:
speakers[-2] = [s]
e.delete(0, END)
spe.config(text=speakers[0])
return
def forward():
if len(speakers) is 0:
return
else:
del speakers[0]
spe.config(text=speakers[0])
return
entry = StringVar()
e = Entry(root, width=30, font=("Arial", 20), textvariable=entry)
e.grid(row=0, sticky=W)
s = e.get()
button1 = Button(root, padx=10, pady=10, bd=5, text='Add', fg='black', command=add)
button1.grid(row=0, column=1)
button2 = Button(root, padx=10, pady=10, bd=5, text='Next', fg='black', command=forward)
button2.grid(row=1, column=1)
n = Label(root, font=("Arial", 35), bd=2, text=spe)
n.grid(row=1, sticky=W)
listdisplay = Label(root, font=('Arial', 20), text=speakers)
listdisplay.grid(row=0, column=10)
root.mainloop()
Is this the sort of thing you were looking for ?
from tkinter import *
root = Tk()
root.title('Speakers List')
root.minsize(800, 600)
speakers = ['50']
spe = speakers[0]
def add():
entry=e.get()
speakers.append(entry)
listdisplay.config(text=speakers)
return
def forward():
if len(speakers) is 0:
return
else:
del speakers[0]
listdisplay.config(text=speakers)
spe=speakers[0]
n.config(text=spe)
return
entry = StringVar()
e = Entry(root, width=30, font=("Arial", 20), textvariable=entry)
e.grid(row=0, sticky=W)
s = e.get()
button1 = Button(root, padx=10, pady=10, bd=5, text='Add', fg='black',command=add)
button1.grid(row=0, column=1)
button2 = Button(root, padx=10, pady=10, bd=5, text='Next', fg='black',command=forward)
button2.grid(row=1, column=1)
n = Label(root, font=("Arial", 35), bd=2, text=spe)
n.grid(row=1, sticky=W)
listdisplay = Label(root, font=('Arial', 20), text=speakers)
listdisplay.grid(row=0, column=10)
root.mainloop()
If so:
You create a list and then you use the append function to add an item to it. The rest was pretty much right.

Python tkinter, clearing an Entry widget from a class

This is the class I'm calling and the function from a different file
class CalcFunc:
def clearScreen(self):
self.log("CLEAR (CE)")
ent.delete(0, END)
This is the Entry Box
ent = Entry(root, textvariable=clc.getBtn, justify=RIGHT, font=10, relief=RIDGE, bd=2, width=15)
ent.grid(row=0, columnspan=3, pady=10)
This is the button I'm clicking to clear the Entry Box
buttonCC = Button(root, text="CLEAR (CE)", height=1, width=20, bg='orange', command=clc.clearScreen)
I'm not sure what the syntax is to be able to to clear an Entry widget from a class basically. That code worked when I had it in the same file but my project requires it to be in a separate file. It's a class project for a calculator and the "clear" button clears the Entry widget. I can post my entire code if that helps. Thank you.
----EDIT----
My Class
import time
class CalcFunc:
def log(self, val):
myFile = open(r".\log.dat", "a")
myFile.write("%s\n" % val)
myFile.close()
def onScreen(self, iVal):
self.log(iVal)
currentTxt = self.getBtn.get()
updateEnt = self.getBtn.set(currentTxt + iVal)
def clearScreen(self):
self.log("CLEAR (CE)")
ent.delete(0, END)
def evaL(self):
self.log("=")
self.getBtn.set(str(eval(self.getBtn.get())))
self.log(self.getBtn.get())
def logLbl(self):
myFile = open(r".\log.dat", "a")
myFile.write("\n==================================\n")
myFile.write("Date: " + str(time.strftime("%m/%d/%Y")) + " -- Time: " + str(time.strftime("%I:%M:%S")))
myFile.write("\n==================================\n")
myFile.close()
My Program
from tkinter import *
import time
import clcClass
root = Tk()
root.title('skClc v1')
clc = clcClass.CalcFunc()
clc.logLbl()
clc.getBtn = StringVar()
ent = Entry(root, textvariable=clc.getBtn, justify=RIGHT, font=10, relief=RIDGE, bd=2, width=15)
ent.grid(row=0, columnspan=3, pady=10)
button1 = Button(root, text="1", height=1, width=5, bg='light blue', command=lambda:clc.onScreen('1'))
button2 = Button(root, text="2", height=1, width=5, bg='light blue', command=lambda:clc.onScreen('2'))
button3 = Button(root, text="3", height=1, width=5, bg='light blue', command=lambda:clc.onScreen('3'))
button4 = Button(root, text="4", height=1, width=5, bg='light blue', command=lambda:clc.onScreen('4'))
button5 = Button(root, text="5", height=1, width=5, bg='light blue', command=lambda:clc.onScreen('5'))
button6 = Button(root, text="6", height=1, width=5, bg='light blue', command=lambda:clc.onScreen('6'))
button7 = Button(root, text="7", height=1, width=5, bg='light blue', command=lambda:clc.onScreen('7'))
button8 = Button(root, text="8", height=1, width=5, bg='light blue', command=lambda:clc.onScreen('8'))
button9 = Button(root, text="9", height=1, width=5, bg='light blue', command=lambda:clc.onScreen('9'))
button0 = Button(root, text="0", height=1, width=5, bg='light blue', command=lambda:onScreen('0'))
buttonP = Button(root, text="+", height=1, width=5, bg='gray', command=lambda:clc.onScreen('+'))
buttonM = Button(root, text="-", height=1, width=5, bg='gray', command=lambda:clc.onScreen('-'))
buttonMM = Button(root, text="x", height=1, width=5, bg='gray', command=lambda:clc.onScreen('*'))
buttonDD = Button(root, text="÷", height=1, width=5, bg='gray', command=lambda:clc.onScreen('/'))
buttonEE = Button(root, text="=", height=1, width=5, bg='light green', command=clc.evaL)
buttonCC = Button(root, text="CLEAR (CE)", height=1, width=20, bg='orange', command=clc.clearScreen)
button1.grid(row=1, column=0, pady=5)
button2.grid(row=1, column=1, pady=5)
button3.grid(row=1, column=2, pady=5)
button4.grid(row=2, column=0, pady=5)
button5.grid(row=2, column=1, pady=5)
button6.grid(row=2, column=2, pady=5)
button7.grid(row=3, column=0, pady=5)
button8.grid(row=3, column=1, pady=5)
button9.grid(row=3, column=2, pady=5)
button0.grid(row=4, column=0, pady=5)
buttonP.grid(row=4, column=1, pady=5)
buttonM.grid(row=4, column=2, pady=5)
buttonEE.grid(row=5, column=0, pady=5)
buttonDD.grid(row=5, column=1, pady=5)
buttonMM.grid(row=5, column=2, pady=5)
buttonCC.grid(row=6, column=0, pady=5, columnspan=3)
root.maxsize(140,245);
root.minsize(140,245);
root.mainloop()
ent = Entry(root, ....)
clc = clcClass.CalcFunc(ent)
class CalcFunc:
def __init__(self, entry):
self.entry = entry
def clearScreen(self):
self.log("CLEAR (CE)")
self.entry.delete(0, END)
Here's an abbreviated example:
#my_entry.py
from tkinter import END
import time
class EntryWithLogger:
def __init__(self, entry):
self.entry = entry
def log(self, val):
with open("log.dat", "a") as my_file: #Automatically closes the file--even if an exception occurs, which is not the case with my_file.close().
my_file.write("%s\n" % val)
def onScreen(self, i_val):
self.log(i_val)
self.entry.insert(END, i_val)
def clearScreen(self):
self.log("CLEAR (CE)")
self.entry.delete(0, END)
Note that I didn't use a StringVar(), which doesn't appear to be necessary. If you need it, you can always pass it as an argument to __init__(), then store it on self.
import my_entry as me
import tkinter as tk
root = tk.Tk()
root.title("Calculator")
root.geometry("+100+50") #("300x500+200+10") dimension, position
entry = tk.Entry(root, justify=tk.RIGHT, font=10, relief=tk.RIDGE, bd=2, width=15)
entry.grid(row=0, columnspan=3, pady=10)
entry_with_logger = me.EntryWithLogger(entry)
#Create the buttons in a loop:
for i in range(10):
row_num, col_num = divmod(i, 3) #divmod(7, 2) => (3, 1), divmod(0, 3) => (0, 0), divmod(4, 3) => (1, 1)
row_num += 1
button_text = str(i)
tk.Button(root, text=button_text,
height=1,
width=5,
bg='light blue',
command=lambda x=button_text: entry_with_logger.onScreen(x)
).grid(row=row_num, column=col_num, pady=5)
#Put the clear button at the bottom of the grid:
tk.Button(root, text="CLEAR (CE)",
height=1,
width=20,
bg='orange',
command=entry_with_logger.clearScreen
).grid(row=row_num+1, columnspan=3) #columnspan tells grid() to use 3 cells for the button,
#and the button will be centered by default.
root.mainloop()
Or, you could do it like this:
#my_entry.py
from tkinter import Entry, END
import time
class EntryWithLogger(Entry):
#Because __init__() is not implemented, the parent class's __init__() gets
#called, so you create an EntryWithLogger just like you would an Entry.
def log(self, val):
with open("log.dat", "a") as my_file: #Automatically closes the file--even if there is an exception, which is not the case with my_file.close().
my_file.write("%s\n" % val)
def onScreen(self, i_val):
self.log(i_val)
self.insert(END, i_val)
def clearScreen(self):
self.log("CLEAR (CE)")
self.delete(0, END)
import my_entry as me
import tkinter as tk
root = tk.Tk()
root.title("Calculator")
root.geometry("+100+50") #("300x500+200+10") dimension, position
entry = me.EntryWithLogger(root, justify=tk.RIGHT, font=10, relief=tk.RIDGE, bd=2, width=15)
entry.grid(row=0, columnspan=3, pady=10)
#Create the buttons in a loop:
for i in range(10):
row_num, col_num = divmod(i, 3) #divmod(7, 2) => (3, 1), divmod(0, 3) => (0, 0), divmod(4, 3) => (1, 1)
row_num += 1
button_text = str(i)
tk.Button(root, text=button_text,
height=1,
width=5,
bg='LightBlue',
command=lambda x=button_text: entry.onScreen(x)
).grid(row=row_num, column=col_num, pady=5)
#Put the clear button at the bottom of the grid:
tk.Button(root, text="CLEAR (CE)",
height=1,
width=20,
bg='orange',
command=entry.clearScreen
).grid(row=row_num+1, columnspan=3) #columnspan tells grid() to use 3 cells for the button,
#and the button will be centered by default.
root.mainloop()

Python Tkinter Entry() Calculations

I am currently trying to build a GUI calculator using python with the help of tkinter. I have managed to set up all of my buttons and they interact with my entry() bar when I press the button (e,g: Press button 5 and 5 appears into the entry()).
The only thing left to do is actually perform the mathematical equations that appear in the entry(). For example, if I enter 5 + 5 * 2 into the entry bar, how would I make the answer appear into the entry() after it's updated? So basically all I'm asking is someone to help me make this happen!
I have provided the code below and a screenshot of the calculator. Also please don't report this as a duplicate or flag this question as a post, (I'm reasking this question because I got no help on my last one so please help a young python programmer out!). Also I'm asking you not to provide me with links because I've read every possible link on tkinter there is to read and still have no clue what I'm doing.
Here is my code:
import sys
from tkinter import *
from PIL import Image, ImageTk
#ACTIONS:
def clear():
#Action: Clears the entry().
txtDisplay.delete(0,END);
return;
def update_Entry(inputValue):
#Updates the entry when a button is pressed.
currentText = num1.get();
update = num1.set(currentText + inputValue);
#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, justify=RIGHT);
txtDisplay.place(x=15, y=10);
txtDisplay.focus();
print(txtDisplay.get())
#Buttons:
zeroButton = Button(root, text='0', width=20, height=3, bg='LightBlue', fg='red', command=lambda:update_Entry('0'));
zeroButton.place(x=17,y=382);
oneButton = Button(root, text='1', width=8, height=3, bg='LightBlue', fg='red', command=lambda:update_Entry('1'));
oneButton.place(x=17, y=302);
twoButton = Button(root, text='2', width=8, height=3, bg='LightBlue', fg='red', command=lambda:update_Entry('2'));
twoButton.place(x=100, y=302);
threeButton = Button(root, text='3', width=8, height=3, bg='LightBlue', fg='red', command=lambda:update_Entry('3'));
threeButton.place(x=182, y=302);
fourButton = Button(root, text='4', width=8, height=3, bg='LightBlue', fg='red', command=lambda:update_Entry('4'));
fourButton.place(x=17, y=222);
fiveButton = Button(root, text='5', width=8, height=3, bg='LightBlue', fg='red', command=lambda:update_Entry('5'));
fiveButton.place(x=100, y=222);
sixButton = Button(root, text='6', width=8, height=3, bg='LightBlue', fg='red', command=lambda:update_Entry('6'));
sixButton.place(x=182, y=222);
sevenButton = Button(root, text='7', width=8, height=3, bg='LightBlue', fg='red', command=lambda:update_Entry('7'));
sevenButton.place(x=17, y=142);
eightButton = Button(root, text='8', width=8, height=3, bg='LightBlue', fg='red', command=lambda:update_Entry('8'));
eightButton.place(x=100, y=142);
ninthButton = Button(root, text='9', width=8, height=3, bg='LightBlue', fg='red', command=lambda:update_Entry('9'));
ninthButton.place(x=182, y=142);
decimalButton = Button(root, text='.', width=8, height=3, bg='powder blue', command=lambda:update_Entry('.'));
decimalButton.place(x=182, y=382);
equalButton = Button(root, text='=', width=8, height=8, bg='Lightgreen', command=lambda:update_Entry('='));
equalButton.place(x=264, y=307);
plusButton = Button(root, text='+', width=8, height=3, bg='gray', command=lambda:update_Entry('+'));
plusButton.place(x=264, y=222);
minusButton = Button(root, text='-', width=8, height=3, bg='gray', command=lambda:update_Entry('-'));
minusButton.place(x=264, y=142);
multiplyButton = Button(root, text='x', width=8, height=3, bg='gray', command=lambda:update_Entry('*'));
multiplyButton.place(x=264, y=66);
divideButton = Button(root, text='÷', width=8, height=3, bg='gray', command=lambda:update_Entry('/'));
divideButton.place(x=182, y=66);
clearButton = Button(root, text='Clear (CE)', width=20, height=3, command = clear, bg='Orange');
clearButton.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();
Screenshot:
For something this simple, try having this as the command for your equalButton:
def evaluate():
currentText = num1.get()
try:
num1.set(str(eval(currentText)))
except SyntaxError:
num1.set('<ERROR>')

Categories