Tkinter

How to Close a Tkinter Window With a Button

In this tutorial, we are going to see how to close a Tkinter window with a Button. We can use a function or command associated with a button in the Tkinter GUI to close a Tkinter window when the user clicks on it.

Tkinter supports a variety of methods to perform various tasks.

destroy() is a common widget method, i.e. we can use this method with any available widgets as well as with the main Tkinter window.
 

 

How to Close a Tkinter Window With a Button

In the following example, destroy() method is passed as a command.

from tkinter import *   

root = Tk()  
root.geometry('200x100')  

#Button
btn = Button(root, text ="Close", command = root.destroy) 
btn.pack(pady = 10) 

root.mainloop()

Output:


 
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *