Ipywidgets: Question: Bind key-press (hotkey) to activate widget event

Created on 18 Jan 2019  路  2Comments  路  Source: jupyter-widgets/ipywidgets

Hello, I have a question. Let's say I create a simple widget in Jupyter, like the button from the documentation.

from IPython.display import display
button = widgets.Button(description="Click Me!")
display(button)

def on_button_clicked(b):
    print("Button clicked.")

button.on_click(on_button_clicked)

Now, I want this button to activate whenever I press a certain hotkey on the keyboard, let's say one of the arrow keys. Is there any possibility of doing this? If not, are there any alternative approaches? Packages or documentation I have missed?

Best regards,
Bj酶rn

Most helpful comment

The only jupyter widget I know of that has been used to assign arbitrary hotkeys from the user is the https://github.com/mwcraig/ipyevents project.

All 2 comments

The only jupyter widget I know of that has been used to assign arbitrary hotkeys from the user is the https://github.com/mwcraig/ipyevents project.

ipyevents looks great, but unfortunately has this limitation:
"The keyboard events are triggered only if the mouse is over the widget."

Is there another work around this issue? It would be great to have a hotkey option to trigger callbacks when defining on_click, observe, etc...

Was this page helpful?
0 / 5 - 0 ratings