I am writing a function to allow the user the select from a series of options and then return values based on these selections. I am using Jupyter Widgets
for the selection and running in JupyterLab. My selection function works fine on its own, but once it has been embedded in another function, it stops to working. Example:
import ipywidgets as widgets
def get_choices():
selections = [
widgets.ToggleButtons(
options=['Not Included', 'Included', 'Favorite'],
description=f"{choice}",
disabled=False,
style= {'description_width': '300px'}
)
for choice in ['choice1', 'choice2', 'choice3']
]
for e in selections:
display(e)
## waiting for user input
print("\n\nPRESS ENTER WHEN FINISHED")
input()
return wiki_edges_select
choices = get_choices()
print(choices)
>> [ToggleButtons(description='choice1', index=1, options=('Not Included', 'Included', 'Favorite'), style=ToggleButtonsStyle(description_width='300px'), value='Included'),
ToggleButtons(description='choice2', index=1, options=('Not Included', 'Included', 'Favorite'), style=ToggleButtonsStyle(description_width='300px'), value='Included'),
ToggleButtons(description='choice3', index=2, options=('Not Included', 'Included', 'Favorite'), style=ToggleButtonsStyle(description_width='300px'), value='Favorite')]
(Note that the values are Included
, Included
, Favorite
). However, when embedded in a wrapper function:
def get_choices_and_process():
choices = get_choices()
print(choices)
get_choices_and_process()
>> [ToggleButtons(description='choice1', options=('Not Included', 'Included', 'Favorite'), style=ToggleButtonsStyle(description_width='300px'), value='Not Included'), ToggleButtons(description='choice2', options=('Not Included', 'Included', 'Favorite'), style=ToggleButtonsStyle(description_width='300px'), value='Not Included'), ToggleButtons(description='choice3', options=('Not Included', 'Included', 'Favorite'), style=ToggleButtonsStyle(description_width='300px'), value='Not Included')]
(Note that the values are Not Included
, Not Included
, Not Included
)
I would like to have the choices
returned within the get_choices_and_process()
function reflect the user's selections as they do when get_choices()
is called outside of the wrapper. How can I make this work?