使用交互时的小部件布局 [英] widget layout when using interact

查看:128
本文介绍了使用交互时的小部件布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在使用交互时使用容器窗口小部件来控制布局?
例如,我希望那些2选择在HBox中。

How can I use a container widget to control the layout while using interact? For instance, I'd like those 2 Select to be in a 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


推荐答案

使用交互式而非交互式找到解决方案

Found a solution using interactive instead of interact

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 )

这篇关于使用交互时的小部件布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆