Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete all children elements?

Tags:

I am writing a GUI-based program using Python's tkinter library. I am facing a problem: I need to delete all children elements (without deleting a parent element, which in my case is colorsFrame).

My code:

infoFrame = Frame(toolsFrame, height = 50, bd = 5, bg = 'white') colorsFrame = Frame(toolsFrame)  # adding some elements  infoFrame.pack(side = 'top', fill = 'both') colorsFrame.pack(side = 'top', fill = 'both')  # set the clear button Button(buttonsFrame, text = "Clear area",                command = self.clearArea).place(x = 280, y = 10, height = 30) 

How do I achieve this?

like image 529
Roman Nazarkin Avatar asked Apr 14 '13 04:04

Roman Nazarkin


People also ask

How do you delete a child in XML?

XML DOM removeChild() Method The removeChild() method removes a specified child node from the current node. Tip: The removed child node can be inserted later into any element in the same document.

Will remove all child nodes of the set of matched elements from the DOM?

The empty() method removes all child nodes from the set of matched elements.


1 Answers

You can use winfo_children to get a list of all children of a particular widget, which you can then iterate over:

for child in infoFrame.winfo_children():     child.destroy() 
like image 120
Bryan Oakley Avatar answered Sep 28 '22 09:09

Bryan Oakley