question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to add new items to a HBox after being created

See original GitHub issue

What 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jasongroutcommented, Oct 20, 2017

If you preferred, in python 3 you can also use a splatting syntax to create the new tuple: HorizBox.children = (*HorizBox.children, NewLabelWidget)

0reactions
jasongroutcommented, Oct 23, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found