ipywidgets – 如何使用包含小部件的Box进行交互?

使用交互式对于多个小部件非常简单,例如:

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

但是,我想使用VBox和HBox的组合以特定方式布局这些小部件.问题是,我如何使用盒子的交互?

我尝试了几种方法,比如使用Box的小部件调用交互式,然后显示盒子本身,但这似乎不起作用.

最佳答案 它位于小部件
documentation中:

In addition to interact, IPython provides another function, interactive, that is useful when you want to reuse the widgets that are produced or access the data that is bound to the UI controls.
[…]
Unlike interact, interactive returns a Widget instance rather than immediately displaying the widget. The widget is a Box, which is a container for other widgets.

所以在这里你已经有了w作为Box容器,您可以为其更改布局属性.

w = interactive(foo, w1=widget1, w2=widget2)
点赞