【发布时间】:2017-07-31 14:25:02
【问题描述】:
我想用 ipywidgets 制作一个交互式模块。 到目前为止一切顺利,但我被困住了。 我想根据特定情况隐藏某个 ipywidget 对象的可见性,并且我希望我的打印文本显示在小部件上方并留在那里。
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)
现在的作用: 在下拉菜单中选中“其他”时,会出现一个文本框,用户可以在其中输入内容。 但是,当检查另一台机器时,文本框会停留在那里。 我只需要一个“隐藏”功能,但我似乎找不到一个有效的功能。
此外,在检查下拉菜单上的另一个选项后,打印消失,不再返回。
【问题讨论】:
标签: python text widget visibility dropdown