Text input reset focus

1,376 views
Skip to first unread message

Kurt Dally

unread,
Feb 6, 2014, 9:17:17 AM2/6/14
to kivy-...@googlegroups.com
I'm working with a TextInput widget and can't figure out why all the below works, except the last line.  I am using the Enter Key on the keyboard and I lose focus every time I hit "Enter", read about this a bit in the docs, yet the last line I thought would bring the focus back.


def on_text_validate(self):

        self.ids.lbl0.text = self.prog.takeTest02(self.ids.inpt0.text)
        self.ids.inpt0.text = ""
        self.ids.inpt0.focus = True

qua-non non

unread,
Feb 6, 2014, 3:16:40 PM2/6/14
to kivy-...@googlegroups.com
The focus for the TextInput hasn't yet been lost by the time you set it again.
You should reset the focus in a function delayed till next frame so the focus is reset after you loose it.

Clock.schedule_once(self._refocus_ti)

def refocus_ti(self,*args):
   self.ids.inpt0.focus = True


Best Regards


--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Kurt Dally

unread,
Feb 10, 2014, 8:06:09 PM2/10/14
to kivy-...@googlegroups.com
 Thanks, This worked great and now I can move along.

- please take not of the _  before the word refocus.

Surendrababu Nallagorla

unread,
Jul 22, 2016, 4:30:38 AM7/22/16
to Kivy users support
Hello Guys,
Could you pls help me, how to use Clock.schedule_once in my program.
pls do the needful.

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
Builder.load_string('''
<MainScreen>:
BoxLayout:
orientation: 'vertical'
BoxLayout:
BoxLayout:
TextInput:
id: Image_Input
multiline: False
focus: True
on_text_validate: Image_Input.focus=True
Button:
on_press:Image_Input.focus=True
text: 'RELOAD'
on_press: root.reload(); Image_Input.text='' 
                                        on_press: Image_Input.focus=True 
''')

class MainScreen(Screen):
def reload(self):
print("screen reloaded")
pass
class TestApp(App):
    def build(self):
        # Create the screen manager
        screenManager = ScreenManager()
        screenManager.add_widget(MainScreen(name='main'))
        return screenManager

if __name__ == '__main__':
    TestApp().run()

ZenCODE

unread,
Jul 22, 2016, 11:16:42 AM7/22/16
to Kivy users support
@Surendrababu Nallagorla

What? We want to help, but we a need en explanation of what the problems is....

Surendrababu Nallagorla

unread,
Jul 22, 2016, 9:48:16 PM7/22/16
to Kivy users support
Hello ZenCode,
issue is: I am able clear the testInput, but cursor is not focusing in the TextInput.
if you copy mode code and execute, it is allowing to enter the TextInput, after pressing RELOAD button, text in textInput is clearing but cusor is not focusing in the textInput.
could you pls help me by correcting my code to make sure refocus in TextInput after RELOAD.

thanks 
Surendra n

ZenCODE

unread,
Jul 23, 2016, 10:36:59 AM7/23/16
to Kivy users support
What code? Please post the code you are using so we can help....

Surendrababu Nallagorla

unread,
Jul 23, 2016, 9:40:03 PM7/23/16
to Kivy users support
Reply all
Reply to author
Forward
0 new messages