0
Why can't I use time.sleep with tkinter
I wanted the label to display red color then blue after a second but that's not happening from tkinter import* import time w=Tk() l=Label(w) l.pack() while True: l.config(bg='red') time.sleep(1) l.config(bg='blue') w.mainloop()
3 odpowiedzi
+ 5
from time import time, sleep
from Tkinter import *
refer to stackoverflow
https://stackoverflow.com/a/10393929/7218253
+ 1
Most tkinter widgets have a method widgetname.after().This takes in the time in microseconds and a callback function
For example,
from tkinter import *
root = Tk()
label = Label(root,bg='red')
label.pack()
def change_color():
label.config(bg='blue')
label.after(200,change_color)
root.mainloop()
0
//Where did you tried sololearn code playground or in external IDE