How to add new items to a HBox after being created
See original GitHub issueWhat would be the best way to add new items to an HBox once again being instantiated and displayed.
import ipywidgets as widgets
from IPython.display import display
HeaderLabels = ['Column-1', 'Column-2', 'Column-3']
HeaderWidgets= [widgets.Label(Text) for Text in HeaderLabels]
HorizBox = widgets.HBox(HeaderWidgets)
display(HorizBox)
After some selection in another widget it is needed to add a new label to the HBox. The only way I have found to do this is (in the change value event called function) to close it and recreate a new one to be displayed. This is,
NewHeaderWidgets=list(HorizBox.children)
HorizBox.close()
NewLabelWidget=widgets.Label('New Column')
NewHeaderWidgets.append(NewLabelWidget)
NewHorizBox = widgets.HBox(NewHeaderWidgets)
display(NewHorizBox, , display_id="1")
This works, but there is another straightforward method to do that? I hope to find a method like
HorizBox.children.append(NewLabelWidget) # but it is an inmutable tuple an raise an error
also i have tried to update the display, but the output header is duplicated (the old one is not erased)
HorizBox.children=tuple(list(HorizBox.children).append(widgets.Label('New Column')))
update_display(NewHorizBox , display_id="1")
It is possible to redisplay the HBox representation with the update in the same cell?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
HBox (JavaFX 8) - Oracle Help Center
HBox lays out its children in a single horizontal row. If the hbox has a border and/or padding set, then the contents will...
Read more >Adding buttons to Hbox - javafx - Stack Overflow
Here is a runnable example as said in the comments check your imports import javafx.application.Application; import javafx.scene.
Read more >JavaFX | HBox Class - GeeksforGeeks
Set the alignment of the HBox using the setAlignment() function. Then create a label and add it to the hbox. Add some buttons...
Read more >JavaFX HBox - Jenkov.com
You create an HBox using its constructor like this: HBox hbox = new HBox();. HBox also has a constructor which takes a variable...
Read more >Layout Panes HBox - JavaFX - Tutorialspoint
The following program is an example of the HBox layout. ... //creating a text field TextField textField = new TextField(); //Creating the play...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If you preferred, in python 3 you can also use a splatting syntax to create the new tuple:
HorizBox.children = (*HorizBox.children, NewLabelWidget)
Great! I’m closing this issue as answered, but feel free to open other issues for other questions, or ask on our gitter channel, etc.