Tab/Enter (and other keystrokes) handling in Kivy's TextInput widgets

minder picture minder · Aug 20, 2012 · Viewed 12.1k times · Source

I'm writing an app using Kivy framework and I stumbled upon a minor but annoying problem: I don't know how to handle Tab/Enter/Arrow keys in text fields so that pressing either of them would dispatch an event, eg. switch the focus (jump) to another TextInput or launch something like send_form()

Could anyone please shed some light on this issue?

Answer

mcastle picture mcastle · Feb 22, 2015

Kivy 1.9 provides the ability to set write_tab: False on text inputs (see docs), causing the tab key to focus on the next focusable widget.

Kivy allows the Enter key to dispatch events by setting multiline: False and on_text_validate: root.foo().

So, to create a text input widget that has the desired Enter and Tab functionality, do as follows:

TextInput:
    write_tab: False
    multiline: False
    on_text_validate: root.foo()