In your code, the label is placed, and after 2 seconds it is destroyed. It is never actually shown in your window however as it is not updated.
This is as when entering Tk’s mainloop
, it updates the window in a loop, checking if changes have been made. In your case, you are preventing this check by using time.sleep
.
With Tkinter, when wanting to have timings you should always use the after
method, to arrange everything in terms of Tkinter’s mainloop (This uses milliseconds).
To fix your code, you could add root.update()
after placing your label. The time.sleep
would still freeze up the mainloop whilst it is waiting however, so a better solution would be to remove the call to sleep, and instead call destroy
on your label after 2 seconds.
This would look like root.after(2000, letsgolabel.destroy)
.
*Note that I have been referring to root as your access to tk.Tk()
, as this is normally used.
0
solved Tkinter Placing And Deleting A Label