Automatically close window after a certain time

前端 未结 2 1934
失恋的感觉
失恋的感觉 2021-01-04 22:42

In a class, in a function I am creating a Tkinter Canvas. This function is being called by another class, I would like for the Tkinter window to pop up for 30 seconds and th

2条回答
  •  攒了一身酷
    2021-01-04 23:11

    Don't use time.sleep() with tkinter. Instead, call the function after on the widget you want to close.

    Here it is the most simple example:

    import tkinter as tk
    
    w = tk.Tk()
    w.after(30000, lambda: w.destroy()) # Destroy the widget after 30 seconds
    w.mainloop()
    

提交回复
热议问题