Thursday, October 2, 2025
HomeLanguagesHow to close a window in Tkinter?

How to close a window in Tkinter?

Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter is the fastest and easiest way to create GUI applications. Creating a GUI using tkinter is an easy task.

To close a tkinter window, we can use the destroy() method. The destroy() is a universal widget method i.e we can use this method with any of the available widgets as well as with the main tkinter window.

Example:

In the below example, we are going to implement the destroy() method using a button.  

Python




# import required module 
from tkinter import *
  
# create object
root = Tk()
  
# create button to implement destroy()
Button(root, text="Quit", command=root.destroy).pack()
  
root.mainloop()


Output:

In the above example, on clicking the button the destroy() method is called and the tkinter window is closed.

RELATED ARTICLES

Most Popular

Dominic
32331 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11927 POSTS0 COMMENTS
Shaida Kate Naidoo
6818 POSTS0 COMMENTS
Ted Musemwa
7080 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS