0

Currently I am working on a pretty major data project. I use the database query to reach for all the important data. I am using one of the tables to create a dropdown menu which would allow me to further process and visualize. The widget itself is already created and working just fine. But there is a problem reaching the key.

I have tried to reach the 'widgets.Dropdown.value' with success, but I am having problem reaching aforementioned respective key that was selected in the dropdown menu.

The code is as follows:

widget_frame = query_all_players(session)
widget_frame = widget_frame.set_index('nick')['id'].to_dict()
dropdown_menu = widgets.Dropdown(options=widget_frame, description='Choose a player')

All of this results in a perfectly working widget:

(No 10 reputation no image I guess - Cheers)

The result I am aiming for is reaching the key in a string format. I'd like to re-use it in some calculation functions.

Kaszanas
  • 446
  • 4
  • 18

1 Answers1

1

I think you are looking for the widget.label variable:

    import ipywidgets as widgets
    w = widgets.Dropdown(
        options=[('One', 1), ('Two', 2), ('Three', 3)],
        value=2,
        description='Number:',
    )
    display(w)
    print(w.label, w.value)

enter image description here

ac24
  • 5,325
  • 1
  • 16
  • 31
  • This is the key! Literally as I am passing a dictionary to the widgets.Dropdown. I guess that I could probably reach that more easily with a debugger just inspecting the object and its properties. Couldn't find that in the docs. – Kaszanas Jul 03 '19 at 15:38