Display a label depending on a timer with tkinter

It is because sleep() will block tkinter from updating. Use after() instead:

from tkinter import *

root=Tk()

touracc=StringVar()
printer=Label(root, textvariable=touracc,bg="#85c17e")
printer.pack()
touracc.set('yo')

def update(n=0):
    if n < 2:    
        touracc.set(n)
        root.after(2000, update, n+1)

root.after(2000, update)
root.mainloop()

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top