- 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
Function to close the window in Tkinter
Whenever we run a tkinter application, it displays a GUI-based window that would have widgets, frames, and other elements. Let us suppose we want to close our application with a function. The destroy() method in Python tkinter is used to terminate the normal execution of the application after the mainloop function.
In this example, will create a button object which triggers to close the application.
#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("650x250") #Define a function def close_app(): win.destroy() #Create a text Label Label(win, text= "Click to close the Window", font= ('Helvetica bold', 14)).pack(pady=20) #Create a Button for closing the window button= Button(win, text= "Close", command= close_app, font=('Helvetica bold', 10)) button.pack(pady=10) win.mainloop()
Running the above code will display a window that contains a button that can be used to close the window.
Now, you can click on the “Close” button to close the window.
- How to close only the TopLevel window in Python Tkinter?
- How do I close a tkinter window?
- How do I handle the window close event in Tkinter?
- How to bind the Escape key to close a window in Tkinter?
- Automatically close window after a certain time in Tkinter
- How to close a Tkinter window by pressing a Button?
- How to close the pop up window in selenium running?
- How to keep the window focus on the new Toplevel() window in Tkinter?
- How to draw images in the Tkinter window?
- How to close the whole browser window by keeping the webDriver active?
- Tkinter-How to get the current date to display in a tkinter window?
- How to make Tkinter Window appear in the taskbar?
- How to put a Toplevel window in front of the main window in Tkinter?
- How to show webcam in TkInter Window?
- How to close child browser window in Selenium WebDriver using Java?