1

I am creating a program with TKinter and am wondering if there is a more efficient way to delete widgets from the window.

I am aware you can delete them 1 by one with:

widget_name.forget()

is there a more efficient and less tedious way to delete them? Like a delete all command?

1 Answers1

3

As has been suggested, if the widgets in question are contained in a parent element like a Frame, "forgetting" the parent will also forget its children.

Another option: if the widgets in question share a parent, you can try the following

# this is useful when you want to keep 'parent' but not its children
# just replace 'parent' with whatever widget's children you want to remove
for widget in parent.winfo_children()
    widget.forget()
JRiggles
  • 4,847
  • 1
  • 12
  • 27