- 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
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().
Example
#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("600x250") #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(): widgets.destroy() #Create a button to close the window Button(frame, text="Clear", font=('Helvetica bold', 10), command= clear_frame).pack(pady=20) win.mainloop()
Output
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.
- Related Articles
- How to gray out (disable) a Tkinter Frame?
- How to clear a Tkinter ListBox?
- How to clear Tkinter Canvas?
- How to clear the contents of a Tkinter Text widget?
- How to clear the Entry widget after a button is pressed in Tkinter?
- How to clear the text field part of ttk.Combobox in tkinter?
- How to clear an entire Treeview with Tkinter?
- How to change the width of a Frame dynamically in Tkinter?
- How to center a Tkinter widget in a sticky frame?
- How to disable (grey out) a checkbutton in Tkinter?
- How to Change Tkinter Frame Title?
- How to place an image into a frame in Tkinter?
- How to place objects in the middle of a frame using tkinter?
- How to put a border around a Frame in Python Tkinter?
- How do I change the background of a Frame in Tkinter?

Advertisements