Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Tkinter clearing a frame

I am trying to clear out a frame in the tkinter so that the new contents can be written (refresh information) but i could not manage to do it. I am aware of these

frame.destroy() frame.pack_forget() frame.grid_forget() 

but frame.destroy() will totally remove the frame. And the other two also could not give me the result i want.What i need is just to clear up every items in the frame but the frame itself will stay. Is there anyway to do it?

like image 635
Chris Aung Avatar asked Apr 03 '13 07:04

Chris Aung


People also ask

How do you clear the screen in tkinter?

While creating a canvas in tkinter, it will effectively eat some memory which needs to be cleared or deleted. In order to clear a canvas, we can use the delete() method. By specifying “all”, we can delete and clear all the canvas that are present in a tkinter frame.

How do you clear a python canvas?

Create the widget adding the argument tags='my_tag' . Then when you want to clear the screen you can do canvas. delete('my_tag') . All canvas widgets tagged with 'my_tag' will be deleted.

How do you clear a label in Python?

If we want to delete a label that is defined in a tkinter application, then we have to use the destroy() method.

How do I refresh tkinter?

You have to exit the program and run it again to show the data. By refresh button you will not need to exit the program. You could kill the root and call it again. May not be the right way, but it will appear as a refresh.


1 Answers

https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/universal.html

w.winfo_children()
Returns a list of all w's children, in their stacking order from lowest (bottom) to highest (top).

for widget in frame.winfo_children():     widget.destroy() 

Will destroy all the widget in your frame. No need for a second frame.

like image 85
Tom.Slick Avatar answered Sep 24 '22 08:09

Tom.Slick