我正在尝试在 Jupyter notebook 中创建一个函数来:
ipywidget
选项列表中的一系列单选按钮。到目前为止,我完成了第 1 步(在下面的 MWE 中名为
radio_buttons
的小部件)并创建了第二个 ipythonwidget
来显示结果(名为 display_result
的小部件,尚未显示上述结果)。我知道我需要将所选结果绑定到display_result
的值(尝试使用函数bind_selected_to_output
)但我不明白如何。
MWE
from ipywidgets import interact, widgets
from IPython.display import display
options=["A","B","C"]
# Tentative function to get the input value into the output widget
def bind_selected_to_output(display):
display.value=#The selected value of radio buttons
# The function I am trying to create
def display_radio_buttons(options):
# Input widget
radio_buttons=widgets.RadioButtons(
options=options,
value=None,
disabled=False
# Output widget
display_result=widgets.Text(description = "Saved as:",
disabled=True)
# Trying to monitor selection on the input widget
radio_buttons.observe(bind_selected_to_output(display_result))
# Show the widgets
display(radio_buttons)
display(display_result)
# Return selected value for use elsewhere
return display_result.value
# Use function
display_radio_buttons(options)
)
我怎样才能使这个功能起作用?