I am trying to make an input widget for a module i have made.
The input widget should have a title bar and a variable number of input lines below. I had in mind to have an add button which should add a line directly below the title line.
I have tried following this stackoverflow question and this issue on github. But these suggestions only add a widget to the bottom of the VBox.
I have made the following dummy example.
import ipywidgets as w
def add_button_clicked(b):
#This adds new line at bottom
#input_box.children += (line(),)
#This is intended to add line below title but does not work
input_box.children = (input_box.children[0], line(), input_box.children[1:])
add = w.Button(icon="plus-circle")
add.on_click(add_button_clicked)
title = w.HBox([w.Label(value=str(i)) for i in range(3)]+[add])
def line():
delete = w.Button(icon="trash")
return w.HBox([w.FloatText(value=i) for i in range(3)]+[delete])
input_box = w.VBox([title,line()])
display(input_box)
However this does not produce a new line as expected. Unfortunately clicking the button does not throw an error.