- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Automatically close window after a certain time in Tkinter
In order to close a Tkinter application, we generally refer to close the parent window using the destroy() method. To close the Tkinter window automatically after a certain time limit, we have to use the after(time in ms, callback) method by specifying the time and the callback function which needs to be run after a certain time limit.
#Import the required Libraries from tkinter import * from tkinter import ttk #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter frame win.geometry("750x270") #Initialize a Label widget Label(win, text= "This window will get closed after 3 seconds...", font=('Helvetica 20 bold')).pack(pady=20) #Automatically close the window after 3 seconds win.after(3000,lambda:win.destroy()) win.mainloop()
Running the above code will display a window that will get closed after 3 seconds.
The given output window will get closed after 3 seconds which can be modified by changing the value in the after (time, callback) method.
- How do I close a tkinter window?
- Creating an automatically maximized tkinter window
- Function to close the window in Tkinter
- How to close a Tkinter window by pressing a Button?
- How to close the ResultSet cursor automatically, after commit in JDBC?
- How do I handle the window close event in Tkinter?
- How to close only the TopLevel window in Python Tkinter?
- How to bind the Escape key to close a window in Tkinter?
- How do we close resources automatically in Java?
- How to hide a widget after some time in Python Tkinter?
- Creating a Transparent window in Python Tkinter
- Creating a Frameless window in Python Tkinter
- Initialize a window as maximized in Tkinter Python
- Window Resizer Control Panel in Tkinter