- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I close a tkinter window?
Creating an application using tkinter is easy but sometimes, it becomes difficult to close the window or the frame without closing it through the button on the title bar. In such cases, we can use the .destroy() method to close the window.
As tkinter attributes are independent of each other, we can create a separate method to close the window using a button.
Example
#Import the library from tkinter import * #Create an instance of window win = Tk() #Set the geometry of the window win.geometry("700x400") #Define a function to close the window def close_win(): win.destroy() #Create a label Label(win, text="Click the button to Close the window", font=('Poppins bold', 25)).pack(pady= 20) #Create a Button Button(win, text= "Close", font=('Poppins bold', 16), command=close_win).pack(pady=20) win.mainloop()
Output
If we run the above code, it will produce the following output window −
- Related Articles
- How do I handle the window close event in Tkinter?
- How do I create a popup window using Tkinter?
- How do I create a popup window in Tkinter?
- How do I open a website in a Tkinter window?
- How to close a Tkinter window by pressing a Button?
- How do I create a popup window using Tkinter Program?
- How do I set a minimum window size in Tkinter?
- How do I position the buttons on a Tkinter window?
- Function to close the window in Tkinter
- How do I insert a JPEG image into a Python Tkinter window?
- Automatically close window after a certain time in Tkinter
- How do I use Window Manager (wm) attributes in Tkinter?
- How do I get the width and height of a Tkinter window?
- How to close only the TopLevel window in Python Tkinter?
- How to bind the Escape key to close a window in Tkinter?

Advertisements