How to clear out a frame in the Tkinter?

Tkinter frames are used to group and organize too many widgets in an aesthetic way. A frame component can contain Button widgets, Entry Widgets, Labels, ScrollBars, and other widgets.

If we want to clear the frame content or delete all the widgets inside the frame, we can use the destroy() method. This method can be invoked by targeting the children of the frame using winfo_children().


#Import the required libraries
from tkinter import *

#Create an instance of tkinter frame
win= Tk()

#Set the geometry of frame

#Create a frame
frame = Frame(win)
frame.pack(side="top", expand=True, fill="both")

#Create a text label
Label(frame,text="Enter the Password", font=('Helvetica',20)).pack(pady=20)

def clear_frame():
   for widgets in frame.winfo_children():

#Create a button to close the window
Button(frame, text="Clear", font=('Helvetica bold', 10), command=



Running the above code will display a window containing a button “Clear” that targets all the widgets inside the frame and clears it.

Now click on the “Clear” Button and it will clear all the widgets inside the frame.