Skip to content Skip to sidebar Skip to footer

How To Add Widgets To Container Widget In Ipython/jupyter

I am trying to make VBox widget and and add a new row with text when button is clicked. I try the following code import ipywidgets as wg from ipywidgets import Layout from IPytho

Solution 1:

You can use a simple plus to concatenate two lists.

vb.children=tuple(list(vb.children) + [new_button])

So your full script will look like this:

import ipywidgets as wg
from ipywidgets import Layout
from IPython.display import display

vb = wg.VBox([wg.Text('1'),wg.Text('2')])
btn = wg.Button(description = 'Add') 

defon_bttn_clicked(b):        
    vb.children=tuple(list(vb.children) + [wg.Text('3')]) 

btn.on_click(on_bttn_clicked)
display(vb, btn)

list(vb.children)

Post a Comment for "How To Add Widgets To Container Widget In Ipython/jupyter"