Arthur Wesley
Arthur Wesley

Reputation: 3

Keyboard events with kivy

I'm trying to create an app where the user can type some text in a TextInput, and press a button to register the data. Is it possible to bind the Enter key, so the user can just press it inside the Text Input and it calls the register function?

Upvotes: 0

Views: 510

Answers (1)

Ari Cooper-Davis
Ari Cooper-Davis

Reputation: 3485

If it's a single line TextInput you can you can set the TextInput.multiline property to False then the Enter key emits a TextInput.on_text_validate() event. For example:

from kivy.uix.textinput import TextInput
textinput = TextInput(text='Hello world')

def on_enter(instance, value):
    print('User pressed enter in', instance)

textinput = TextInput(text='Hello world', multiline=False)
textinput.bind(on_text_validate=on_enter)

This is in Kivy's TextInput documentation.

Upvotes: 0

Related Questions