As you already suggested, you could set the value of the widget to "" after each change:
from IPython.html import widgets
from IPython.display import display
def dropdown_event_handler(change):
print(change.new)
dropdown.value = ""
options = ["", "A", "B"]
dropdown = widgets.Dropdown(options=options, description="Categories")
dropdown.observe(dropdown_event_handler, names='value')
display(dropdown)
And I fear that is your only option. The Dropdown widget has no other type than "change". You can see all available types by printing them with type=All.
from IPython.html import widgets
from IPython.display import display
from traitlets import All
def dropdown_event_handler(change):
print(change)
options = ["", "A", "B"]
dropdown = widgets.Dropdown(options=options, description="Categories")
dropdown.observe(dropdown_event_handler, type=All)
display(dropdown)
Output:
{'name': '_property_lock', 'old': traitlets.Undefined, 'new': {'index': 1}, 'owner': Dropdown(description='Categories', options=('', 'A', 'B'), value=''), 'type': 'change'}
{'name': 'label', 'old': '', 'new': 'A', 'owner': Dropdown(description='Categories', index=1, options=('', 'A', 'B'), value=''), 'type': 'change'}
{'name': 'value', 'old': '', 'new': 'A', 'owner': Dropdown(description='Categories', index=1, options=('', 'A', 'B'), value='A'), 'type': 'change'}
{'name': 'index', 'old': 0, 'new': 1, 'owner': Dropdown(description='Categories', index=1, options=('', 'A', 'B'), value='A'), 'type': 'change'}
{'name': '_property_lock', 'old': {'index': 1}, 'new': {}, 'owner': Dropdown(description='Categories', index=1, options=('', 'A', 'B'), value='A'), 'type': 'change'}
So you can't observe a value in a Dropdown widget if it did not change. For more information see the Traitlets documentation.
on_clickmethod, but you don't click a Dropdown, you choose an option. Sounds like it would be better served by an array ofButtonsfor your different options?