![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 −
Advertisements