我想使用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)
现在的功能是:当下拉菜单中选择“其他”时,会出现一个文本框,用户可以在其中输入内容。但是,当勾选另一台机器时,该文本框仍然存在。我只需要一个“隐藏”功能,但似乎找不到可用的。此外,在下拉菜单中选择另一个选项后,打印内容消失了,不再出现。
boton.layout.visibility = 'hidden'
对我有用!使用boton.layout.visibility = 'visible'
可以使它再次可见。 - Ron Kalian