使用带有选项 manual=True 的 ipywidget interactive()
use ipywidget interactive() with option manual=True
我正在将带有交互式小部件的 jupyter 笔记本更新到更新的版本 (ipywidgets 7.2.1)。
它曾经有 interactive()
功能,这些功能是通过单击按钮手动执行的(功能 __manual=True
)。但是现在我无法重现相同的行为。
这是一个最小的例子:
from ipywidgets import interactive, interact_manual
import ipywidgets as widgets
def do_sth(x):
#do sth with the argument passed
print("done "+str(x))
nb = widgets.BoundedIntText(description='Number:')
#Interaction in accordion nested in a tab
tab = widgets.Tab()
tab.set_title(0, 'Page 1')
#old method
#problem: it is not manual anymore
w = interactive(do_sth, x=nb, __manual=True)
#new solution 1
#problem: the widget appears also outside the tab/accordion
w1 = interact_manual(do_sth, x=nb)
w1.widget.children[1].description = 'do sth' #seems a bit of a hack
#new solution 2
w2 = interactive(do_sth, x=nb, manual=True) #does no pass the manual option
#if I set it manually with:
#w2.manual = True
#It generates an error (AttributeError: 'interactive' object has no attribute 'manual_button')
accordion = widgets.Accordion(children=[w, w1.widget, w2])
accordion.set_title(0, 'old interaction 0')
accordion.set_title(1, 'new interaction 1')
accordion.set_title(2, 'new interaction 2')
tab.children = [accordion]
tab
是否可以使用方案一来防止小部件出现两次?否则,还有其他方法吗?
似乎他们在添加重新标记按钮的功能时可能已将其移动到字典中。
尝试
w2 = interactive(do_sth, {'manual' : True, 'manual_name' : 'Do Something'}, x=nb)
我正在将带有交互式小部件的 jupyter 笔记本更新到更新的版本 (ipywidgets 7.2.1)。
它曾经有 interactive()
功能,这些功能是通过单击按钮手动执行的(功能 __manual=True
)。但是现在我无法重现相同的行为。
这是一个最小的例子:
from ipywidgets import interactive, interact_manual
import ipywidgets as widgets
def do_sth(x):
#do sth with the argument passed
print("done "+str(x))
nb = widgets.BoundedIntText(description='Number:')
#Interaction in accordion nested in a tab
tab = widgets.Tab()
tab.set_title(0, 'Page 1')
#old method
#problem: it is not manual anymore
w = interactive(do_sth, x=nb, __manual=True)
#new solution 1
#problem: the widget appears also outside the tab/accordion
w1 = interact_manual(do_sth, x=nb)
w1.widget.children[1].description = 'do sth' #seems a bit of a hack
#new solution 2
w2 = interactive(do_sth, x=nb, manual=True) #does no pass the manual option
#if I set it manually with:
#w2.manual = True
#It generates an error (AttributeError: 'interactive' object has no attribute 'manual_button')
accordion = widgets.Accordion(children=[w, w1.widget, w2])
accordion.set_title(0, 'old interaction 0')
accordion.set_title(1, 'new interaction 1')
accordion.set_title(2, 'new interaction 2')
tab.children = [accordion]
tab
是否可以使用方案一来防止小部件出现两次?否则,还有其他方法吗?
似乎他们在添加重新标记按钮的功能时可能已将其移动到字典中。
尝试
w2 = interactive(do_sth, {'manual' : True, 'manual_name' : 'Do Something'}, x=nb)