I have a problem with tkinter when a label refers to a value and I update the value by pressing a button. The value is indeed updated but the label text referring to this value is not.
How can I change this code that the button updates the value and the label refering to this value is updated and shown in the root
?
import tkinter
root = Tk()
root.title('Test Button')
root.geometry('600x450')
class Letter:
def __init__(self, value):
self.value = value
class Label:
def __init__(self, master):
self.a_label = tkinter.Label(root, text=current_letter.value)
self.a_label.grid(row=2, column=1)
class Button:
def __init__(self, master):
self.Button1 = tkinter.Button(master, height = 12, width = 24,
command= self.update_letter)
self.Button1.grid(row=1, column=1)
def update_letter(self):
current_letter.value
print("current_letter.value before: " + str(current_letter.value))
current_letter.value += 1
print("current_letter.value now: " + str(current_letter.value))
root.update
#initialize a
a = Letter(0)
current_letter = a
b = Button(root)
l = Label(root)
root.mainloop()