How would I make destroy() method in Tkinter work with my code?

TkinterServer Side ProgrammingProgramming

In order to close or remove any widget in an existing Tkinter application, we can use the destroy() method. It terminates the widget process abruptly within the program. The method can be invoked with the specific widget we want to close.


In this example, we will create a button to remove the Label Widget from the application.

#Import required libraries
from tkinter import *
from tkinter import ttk
#Create an instance of Tkinter frame
win= Tk()

#Define the geometry of the window

#Define a function to destroy the label widget
def close_widget():

#Create a label
label= Label(win, text= "Hey There! How are you?", font= ('Helvetica20 italic'))

#Create a Button to remove the Label
ttk.Button(win, text="Remove", command= close_widget).pack(pady=20)


Running the above code will display a window that contains a label widget and a button in it.

Now, click the Remove button to destroy the label widget in the frame.

Updated on 04-May-2021 14:19:28