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.


#Import the library
from tkinter import *

#Create an instance of window
win = Tk()

#Set the geometry of the window

#Define a function to close the window
def close_win():

#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),



If we run the above code, it will produce the following output window −

Updated on: 04-Mar-2021

12K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started