<p>我想用ipywidgets制作一个交互式模块。
到目前为止还不错,但我被卡住了。
我想根据特定情况隐藏特定ipywidget对象的可见性,并且我希望我的打印文本显示在widget上方并保持在那里。在</p>
<pre><code>dropdown=widgets.Dropdown(
options={'Coffee machine': 1, 'Washing machine': 2, 'Water Heater': 3, 'Heating System': 4, 'Dryer': 5, 'Oven': 6, 'Microwave': 7, 'Other':8},
value=1,
description='Apparaat:',
)
text_new=widgets.Text()
def text_field(value):
if(value==8):
display(text_new)
text_new.on_submit(handle_submit)
else:
text_new.visible(False) #Doesn't work but I want something like this
print("Today you had an increase in electricity consumption, would you like to name this device?") #This just be above the dropdown menu and be stuck
i=widgets.interactive(text_field, value=dropdown)
display(i)
</code></pre>
<p>现在的作用是:
当在下拉菜单中选中“其他”时,会出现一个文本框,用户可以在其中键入内容。
但是,当检查另一台机器时,文本框将保留在那里。
我只需要一个“隐藏”功能,但我似乎找不到一个有效的。在</p>
<p>另外,在选中下拉列表中的另一个选项后,打印将消失,不再返回。在</p>