Reputation: 53
I was working on a program testing the .pack_forget() command in TKinter, but encountered a problem. I had a time.sleep() command in my code, and the TKinter window will not open until the time.sleep() command has been executed in IDLE. Here is my code:
from tkinter import *
import time
main = Tk()
main.title("Test")
myLabel = Label(main, text="I'm a Label", fg="black")
myLabel.pack()
time.sleep(3)
myLabel.pack_forget()
If you know why this issue is occurring, please answer.
Upvotes: 0
Views: 41
Reputation: 2711
time.sleep()
puts the entire program to sleep, so that it cannot do anything.
You should instead use:
main.after(3000, myLabel.pack_forget)
to run myLabel.pack_forget()
after 3000 miliseconds, i.e. 3 seconds.
Upvotes: 1