Skip to content

Instantly share code, notes, and snippets.

@botzill
Last active December 19, 2017 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save botzill/1a38b42b5bbfb8b7e9f8c3a2b943102a to your computer and use it in GitHub Desktop.
Save botzill/1a38b42b5bbfb8b7e9f8c3a2b943102a to your computer and use it in GitHub Desktop.
Simple kivy app with text input
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
kv = """
<Test>:
# orientation: 'horizontal'
orientation: 'vertical'
Button:
size_hint: 1, 0.95
text: 'test button'
MyTextInput:
id: text_input
size_hint: 0.5, None
text_hint: 'input message...'
multiline: True
height: self.minimum_height
"""
Builder.load_string(kv)
class MyTextInput(TextInput):
def on_text_validate(self):
App.get_running_app().root.ids.text_input.text = ''
def insert_text(self, substring, from_undo=False):
if substring == '\n':
substring = ''
self.dispatch('on_text_validate')
return super(MyTextInput, self).insert_text(substring, from_undo)
class Test(BoxLayout):
pass
class TestApp(App):
def build(self):
t = Test()
return t
if __name__ == '__main__':
TestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment