I want to close the current window 2 seconds after it appears
if you insert time.sleep(2) before win.mainloop(), the window will not be displayed for 2 seconds, and I need it to open and close after 2 seconds
global win
win = Tk()
win.attributes('-alpha', 0.0)
win.iconify()
window = Toplevel(win)
window.geometry("300x300+" + str(randint(0, 1400)) + "+" + str(randint(0, 700)))
window.overrideredirect(1)
photo = PhotoImage(file="classes/bin/starters/spaceStorage/popUps/" + rand + r".png")
label = Label(window, image=photo)
label.pack()
win.mainloop()
>Solution :
Use .after() instead of time.sleep():
...
# destroy root window after 2 seconds
win.after(2000, win.destroy)
win.mainloop()
Why don’t you just use the root window instead of hiding it and create another toplevel?