user1879926
user1879926

Reputation: 1323

Select dropdown key for ipython widget

In creating an ipython dropdown widget,

from IPython.html import widgets
from IPython.display import display

d = {"1": "a", "2": "b"}

dropdown = widgets.Dropdown(options=d)
display(dropdown)

I can use

print dropdown.value

to print the value of the selected key from the dropdown widget. How can I obtain the key ("1", "2") that is clicked in the dropdown? Using

print dropdown.key

does not work.

Upvotes: 1

Views: 1421

Answers (1)

memoselyk
memoselyk

Reputation: 4118

The key is stored in dropdown.selected_label

I couldnt' find any other reference that this one.

Upvotes: 1

Related Questions