- Trending Categories
- 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
What is the difference between root.destroy() and root.quit() in Tkinter(Python)?
When we invoke the destroy() method with the tkinter window object, it terminates the mainloop process and destroys all the widgets inside the window. Tkinter destroy() method is mainly used to kill and terminate the interpreter running in the background.
However, quit() method can be invoked in order to stop the process after the mainloop() function. We can demonstrate the functionalities of both methods by creating a button Object.
Example
#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("650x450") #Define a function for Button Object def quit_win(): win.quit() def destroy_win(): win.destroy() #Button for Quit Method Button(win,text="Quit", command=quit_win, font=('Helvetica bold',20)).pack(pady=5) #Button for Destroy Method Button(win, text= "Destroy", command=destroy_win, font=('Helvetica bold',20)).pack(pady=5) win.mainloop()
Output
Running the code will display a window with two buttons “Quit” and “Destroy” respectively.
Warning − quit() will terminate the application abruptly, hence it is recommended that you close the application from the manager after execution.
Advertisements