Why can't I use time.sleep with tkinter | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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()

21st Jan 2020, 5:43 PM
Pattern
Pattern - avatar
3 Answers
+ 5
from time import time, sleep from Tkinter import * refer to stackoverflow https://stackoverflow.com/a/10393929/7218253
21st Jan 2020, 5:48 PM
BroFar
BroFar - avatar
+ 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()
25th Jan 2020, 6:13 PM
John
John - avatar
0
//Where did you tried sololearn code playground or in external IDE
21st Jan 2020, 5:47 PM
Sudarshan Rai
Sudarshan Rai - avatar