user8605709
user8605709

Reputation:

How do you get a tkinter window to close automatically after a few seconds delay?

I have a tkinter window, root, which should close after a few seconds delay. Here is the code I currently have for my window:

from tkinter import *
root=Tk()
def WaitAndClose():
    global root
    #close root after a few seconds
Button(root, text='Close', command=WaitAndClose).pack()
mainloop()

EDIT: root.after(,) was the command that worked.

Upvotes: 1

Views: 3804

Answers (2)

Keshab Kumar
Keshab Kumar

Reputation: 11

Code:

from tkinter import *

jha=Tk()

jha.title("auto close window")

jha.geometry("750x600")

jha.after(5000,lambda:jha.destroy())

jha.mainloop()

Upvotes: 0

Miriam
Miriam

Reputation: 2721

The following should close the tkinter window root (change as applicable) after 5000 milliseconds (5 seconds):

root.after(5000, root.destroy)

Upvotes: 5

Related Questions