ipyevents provides a custom widget for capturing and returning mouse and keyboard events from Jupyter widgets to Python. It enables adding interactive features like keyboard shortcuts, reacting to clicks on images, and handling arbitrary mouse/keyboard events within a Jupyter environment. The current version is 2.0.4, targeting JupyterLab 3 and above. Releases are driven by compatibility with JupyterLab versions and feature additions.
pip install ipyeventsVerified import paths — ran on the pinned version, not inferred.
This quickstart creates a Label widget and an Event listener attached to it. It watches for 'click', 'keydown', and 'mouseenter' events, displaying event information in an HTML widget. This demonstrates how to capture browser events and process them in Python.
Ensure your ipyevents version matches your JupyterLab version. Upgrade JupyterLab to version 3+ for ipyevents 2.x, or downgrade ipyevents to 0.9.0 or earlier for JupyterLab 2.
Be aware that keyboard input will be directed to the watched widget. This is intended behavior to prevent accidental notebook actions. You can style the focused element (e.g., with a blue border) to make it clear which element has focus.
Utilize the `throttle_or_debounce` and `wait` parameters of the `Event` widget to limit the rate at which events are passed to Python. 'throttle' is good for `mousemove`/`wheel`, 'debounce' for limiting repeated key strokes or clicks.
If `prevent_default_action` is critical for 'wheel' events, test thoroughly. Consider alternative approaches or monitor the GitHub issues for a fix. There is no direct workaround mentioned in documentation.
Ensure `ipyevents` is installed and the JupyterLab extension is correctly linked. For `ipyevents` 2.0.0+ with JupyterLab 3+, `pip install ipyevents` should be sufficient, as it automatically handles the lab extension. If issues persist, try `jupyter labextension install @jupyter-widgets/jupyterlab-manager ipyevents` and restart JupyterLab.
Install the package using pip: `pip install ipyevents`. If using Anaconda, ensure it's installed in the correct environment or try `conda install -c conda-forge ipyevents`. After installation, restart your Jupyter kernel.
Ensure the widget linked as the `source` for `ipyevents.Event` has focus (e.g., by clicking on it) in the Jupyter interface. Be aware that once `ipyevents` captures a keyboard event, it will not be processed by the notebook itself.
Update `jupyterlab`, `ipywidgets`, and `jupyterlab-widgets` to their latest compatible versions: `pip install -U jupyterlab ipywidgets jupyterlab-widgets`. Clearing your browser cache and restarting JupyterLab might also resolve the issue.