Is there a way to add an id to a widget so that clicking the first submit button modifies the value of responses["set1"] based on the radio buttons in set 1 and likewise for set 2?
I am dynamically generating the number of sets to display so unfortunately can't hard code.
This code as is doesn't work, but hope it demonstrates the spirit of what I'm looking for.
import ipywidgets as widgets # running in google colab
from IPython import display
responses = {"set1": None,
"set2": None}
options = {"this pos": 1, "this neg": -1}
def radio_buttons(options):
return widgets.RadioButtons(
options=options.keys(),
disabled=False
)
def set_answers(obj):
responses[SET_N] = APPROPRIATE RADIO BUTTON VALUE
submit = widgets.Button(description="Submit")
print("set 1")
IPython.display.display(radio_buttons(options))
submit.on_click(set_answers)
IPython.display.display(submit)##any way to set an id to link to set radio_button.value1?
print("set 2")
IPython.display.display(radio_buttons(options))
submit.on_click(set_answers)
IPython.display.display(submit) ##any way to set an id to link to set2 radio_button.value?