Python Forum
[Tkinter] counting in a label
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] counting in a label
#1
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
Reply
#2
Everything before mainloop() happens until you close the Tkinter window. The rest, the counting part, doesn't happen until you exit the GUI.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020