Python Forum

Full Version: counting in a label
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How do I get this to count in the label? It just shows an empty window and gives me an error when I close it.
import time
import tkinter as tk

def sequence():
    root = tk.Tk()
    label = tk.Label(root)
    label.pack()
    root.mainloop()

    t = 0
    msg = f"{t}"
    while True:
        label(root, text=msg)
        t += 1
        time.sleep(3)

if __name__ == "__main__":
    sequence()
Error:
Traceback (most recent call last): File "c:/Users/User/MyStuff/git/Python-doodles/utilities/Temperature_venv/tk_tst.py", line 22, in <module> sequence() File "c:/Users/User/MyStuff/git/Python-doodles/utilities/Temperature_venv/tk_tst.py", line 15, in sequence label(root, text=msg) TypeError: 'Label' object is not callable
Everything before mainloop() happens until you close the Tkinter window. The rest, the counting part, doesn't happen until you exit the GUI.