pythonjupyter-notebookipywidgets

Get Keyboard Events on Jupyter Widgets


I have a text box in Jupyter likes the following:

import ipywidgets as widgets
from IPython.display import display, clear_outpu
tagInput = widgets.Text()

And try to get keyboard events like Enter using the following code:

tagInput.observe(handle_process_text_submit,names='value')

But, it catches just the value changes. what supposed to do to solve the issue?


Solution

  • If You want to catch the keyboard Enter specifically, you can use on_submit event such as the following:

    def on_submit_func(sender):
        print "enter"
    
    tagInput.on_submit(on_submit_func)
    

    Update on January 1st 2025:

    It seems that the issue with observe method has been resolved in recent versions.