How to use interactive with a box containing widgets?

Use is interactivequite simple with multiple widgets, for example:

interactive(foo, w1=widget1, w2=widget2, ...)

However, I would like to compose these widgets in a specific way using combinations of VBox and HBox. The question is, how can I use interative with the box?

I tried several ways, such as calling interactive with Box widgets and then displaying the window itself, but this does not seem to work.

+4
source share
3 answers

In widgets documentation :

interact, IPython interactive, , , . [...] interact, interactive Widget . Box, .

, w Box, .

w = interactive(foo, w1=widget1, w2=widget2)
+1

, interactive_output.

out = interactive_output(foo, {"w1":w1, "w2":w2, "w3":w3, "w4":w4})
vbox1 = VBox([w1, w2])
vbox2 = VBoX([w3, w4])
ui = HBox([vbox1, vbox2])

accordian = Accordian(children=[ui])
accordian.set_title(0, 'Title')

display(accordian, out)
0

interactive_output

- :

t1 = Text(value='Hello 1', description='row 1')
t2 = Text(value='Hello 2', description='')
t3 = Text(value='Hello 3', description='')
t4 = Text(value='Hello 4', description='row 2')
t5 = Text(value='Hello 5', description='')
t6 = Text(value='Hello 6', description='')
t7 = Text(value='Hello 7', description='row 3')
t8 = Text(value='Hello 8', description='')
t9 = Text(value='Hello 9', description='')

def foo(p1,p2,p3,p4,p5,p6,p7,p8,p9):
    print(p1,p2,p3,p4,p5,p6,p7,p8,p9)

out = interactive_output(foo, {"p1":t1, "p2":t2, "p3":t3, "p4":t4, "p5":t5, "p6":t6, "p7":t7, "p8":t8, "p9":t9})
hbox1 = HBox([t1, t2, t3])
hbox2 = HBox([t4, t5, t6])
hbox3 = HBox([t7, t8, t9])
ui = VBox([hbox1, hbox2, hbox3])

display(ui, out)
0

Source: https://habr.com/ru/post/1654050/


All Articles