Is it enough to call widget.close() to remove container widget (like HBox, VBox)? Will the call automatically close child widgets?
Nope, It won't close the child widgets.
To elaborate, each widget exists independent of others. A widget can easily be the child of more than one container, so it doesn't make sense to give ownership to one particular container.
Closing the container will remove the view of the child widget in that container, but it won't close the child widget.
Thank you very much!
I have also connected question: is it possible to walk through controls from child to parents?
I know it is possible to go from parent to children by the help of children property. Is it possible to follow opposite way?
I see property "parent" but it is alsway None
Since one widget can be a child of multiple widgets, it's not possible. Again, the child exists independent of the container, and has no knowledge of the container, and can exist in multiple containers.
PS. It is ok to ask questions like I asked here? Or it is better to use some forum, stackoverflow etc.?
It's not only okay, but encouraged! This is a good place to ask questions because it preserves the questions and answers in a place close to the code.
Closing as resolved. Thanks again for asking!
I have a question concerning (for me) unexpected behavior of widget.close()
In my prototype code for N-dimensional data visualization (ROOT), I'm using user defined array of sliders where user can dynamically append and remove sliders. Removing slider box from the Hbox the HBox(self.fSliderWidgets.children see code below) is working fine - as you discussed above.
sliderArray=TSliderArray()
sliderArray.addSlider('x1(1:2:0.1:1.5:1.75)')
sliderArray.addSlider('x2(10:20:1)')
sliderArray.addSlider('x3(100:200:0.1:110:180)')
Removing box from tuple - rebuilding tuple (see removeSlider)
def addSlider(self, sliderDescription):
....
newBox=widgets.HBox([newSlider,enableButton,removeButton],layout=Layout(width='100%'))
self.fSliderWidgets.children+=(newBox,)
removeButton.on_click(self.removeSlider)
....
def removeSlider(self,b):
# remove parent box (button b) from the tuple
box=self.fSliderDictionary.get(b)
box.close()
self.fSliderWidgets.children=[x for x in self.fSliderWidgets.children if x !=box] #tuple build again removing box
Is problem which I observe expected. I assumed box close should remove references from containers.
Thank you
Marian