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 IPython.display import display
vb = wg.VBox([wg.Text('1'),wg.Text('2')])
btn = wg.Button(description = 'Add')
def on_bttn_clicked(b):
vb.children=tuple(list(vb.children).append(wg.Text('3')))
btn.on_click(on_bttn_clicked)
display(vb, btn)
list(hb.children)
But the assignment "hb.children=" does not work... Is there a way to edit container widgets with code in the same cell?
vb.children=tuple(list(vb.children).append(wg.Text('3'))may be where your main problem is:list(vb.children).append(wg.Text('3')returnNoneand therefore you are passingNoneto thetupleconstructor method. This should, in fact, throw an error. Please share that error here.def on_bttn_clicked(b): temp = list(vb.children) temp.append(wg.Text('3')) vb.children=tempIt works fine now!