I am trying to remove a child widget from an HBox ipython widget group within an ipython notebook. Creating the widget group looks like this:
buttons = [widgets.Button(description=str(i)) for i in range(5)]
mybox = widgets.HBox(children=buttons)
mybox
This displays 5 buttons.
Now I have a group of five buttons and I would like to remove the last button. As far as I can tell the box object does not have a method to remove children. So my thought was to close the last widget in the group:
mybox.children[-1].close()
Now, only the first 4 buttons are displayed (0, 1, 2, 3) which is what I want, however if I get the description from the group the 5th button is still there:
[child.description for child in mybox.children]
['0', '1', '2', '3', '4']
The output I expected, and what I need is this:
['0', '1', '2', '3']
I can simply create a copy of a slice, however this causes other problems, and I would really like to be able to modify the original box.
This is not what I need:
mybox = widgets.HBox(children=mybox.children[:-1])