Last active
December 19, 2017 11:24
-
-
Save botzill/1a38b42b5bbfb8b7e9f8c3a2b943102a to your computer and use it in GitHub Desktop.
Simple kivy app with text input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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