Tkinter Label Updating Issue Tkinter Label Updating Issue tkinter tkinter

Tkinter Label Updating Issue


I believe there is a misunderstanding on how StringVar works. The line

EnteredSetup.set(Entered)

does not create some form of link between EnteredSetup and Entered, modifying Entered does not issue updates in EnteredSetup. Your code can be improved a lot too, and you should post something that is only long enough to describe the problem. Said that, consider this reduced version already fixed (note that it could be much smaller):

from Tkinter import Tk, StringVarimport ttkclass Calculator:    def __init__(self, state):        self.state = state    def ac(self):        self.state.set('')    def state_num(self, num):        self.state.set('%s%d' % (self.state.get(), num))#Main Window Setup:#Root setuproot = Tk()root.title("Generic Calculator")EnteredSetup = StringVar('')calc = Calculator(EnteredSetup)#Parent frame setupmainframe = ttk.Frame(root, padding="8")mainframe.grid(column=0, row=0)mainframe.columnconfigure(0, weight=1)mainframe.rowconfigure(0, weight=1)#Button setupttk.Button(mainframe, text="AC", command=calc.ac).grid(        column=5, row=4)ttk.Button(mainframe, text="1", command=lambda: calc.state_num(1)).grid(        column=1, row=6)ttk.Button(mainframe, text="0", command=lambda: calc.state_num(0)).grid(        column=1, row=7)#Label Setup:ttk.Label(mainframe, textvariable=EnteredSetup).grid(        column=1,row=1,columnspan=5)root.mainloop()

I hope this guides you in the right direction for further adjusting your calculator.