Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic 'focus' of TextInput Kivy

Tags:

python

kivy

I have a textinput widget that looks like this:

<ReaderWidget>:
    Label:
        text: 'Please scan EBT card'
        font_size: root.height/8
        size: self.texture_size
        bold: True
        color: 0, 0.70, 0.93, 1
    TextInput:
        focus: True
        password: True
        multiline: False
        cursor: 0, 0

The widget is dynamically added to the layout based on the user pressing a button in another widget. Currently the user has to point the mouse/finger into the text box before entering text, and I want the cursor to be in the text box ready to receive text without the user having to indicate by mouse press. Is there a way to do this?

It seems like focus : True should do it. But it doesn't seem to.

like image 508
Woody Pride Avatar asked Oct 16 '15 17:10

Woody Pride


1 Answers

I know this is old but I found this question when I was trying to do something very similar. My code for adding the TextInput (and setting it's focus) was in the on_press handler for a button. A press would cause the TextInput to be added to the layout and it's focus set, but then it would lose focus when the button was released. Moving my code to on_release fixed the problem.

like image 98
intrepidhero Avatar answered Sep 23 '22 03:09

intrepidhero