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.

Warningquit() will terminate the application abruptly, hence it is recommended that you close the application from the manager after execution.

Updated on: 26-Mar-2021

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements