Clear TextInput text after input

3,438 views
Skip to first unread message

Yurij Mikhassiak

unread,
Jan 22, 2013, 4:51:11 PM1/22/13
to kivy-...@googlegroups.com
Hello. I know there must be an easy solution as this is a common task but I can't find it.
I have TextInput with corresponding button.

The code is as you see here: 
    
        TextInput:
            id: myinput
            on_text_validate: root.function(myinput.text); 
        
        Button:
            text: 'Execute'
            on_press: root.function(myinput.text)


I want to clear input field after user enters data and press enter or button.
I couldn't find any examples. I think it's possible to use somethink like this:
 TextInput:
            id: myinput
            on_text_validate: root.function(myinput.text); myinput.select_all(); myinput.delete_selection()

But it doesn't work at all. And I even do not know were to look for answer. Can't find select_all() and delete_selection() examples.

Any ideas?
Thanks in advance!


Gabriel Pettier

unread,
Jan 22, 2013, 5:48:38 PM1/22/13
to kivy-...@googlegroups.com
Why not simply assign "" to the text?

on_text_validate: root.function(myinput.text); self.text = ""

cheers :)
> --
>
>


Yurij Mikhassiak

unread,
Jan 23, 2013, 5:19:23 AM1/23/13
to kivy-...@googlegroups.com
It work's perfect this way! Thank you!!!

Середа, 23 січня 2013 р. 00:48:38 UTC+2 користувач tshirtman написав:

Surendrababu Nallagorla

unread,
Jul 20, 2016, 1:41:54 AM7/20/16
to Kivy users support
Hello TShirtman,
I am not able to REFOCUS in TEXTINPUT in next frame., could you pls help me to fix, pls look into my following code.
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='' 
''')

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()
Reply all
Reply to author
Forward
0 new messages