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?
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.
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.
If we want to delete a label that is defined in a tkinter application, then we have to use the destroy() method.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With