如何在使用交互时使用容器小部件来控制布局? 例如,我喜欢那些2选择进入HBox。
from IPython.html import widgets
from IPython.display import display
def f(dl, ft):
print dl, ft
dlW = widgets.Select(options={str(k):k for k in range(4)})
ftW = widgets.Select(options={str(k):k for k in 'ABCD'})
hbox=widgets.HBox([dlW, ftW])
i = widgets.interact(f,
dl = dlW,
ft = ftW
)
# display( hbox ) # <-- commenting in makes the widget display twice
答案 0 :(得分:3)
使用交互式而非交互式
找到解决方案dlW = widgets.Select(options={str(k):k for k in range(4)})
ftW = widgets.Select(options={str(k):k for k in 'ABCD'})
i = widgets.interactive(f,
dl = dlW,
ft = ftW
)
hbox=widgets.HBox(i.children)
display( hbox )