How to read text in kivy textinput or Label - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: How to read text in kivy textinput or Label (/thread-31683.html) |
How to read text in kivy textinput or Label - jadel440 - Dec-27-2020 from kivy.app import App from kivy.lang import Builder from kivy.properties import StringProperty from kivy.uix.textinput import TextInput kv = ''' BoxLayout: orientation: 'vertical' text: newList TextInput: id: newList Button: text: 'click' on_press: app.clicked() ''' class MyApp(App): text = StringProperty('-.text') def build(self): return Builder.load_string(kv) def clicked(self): file = open('-.text', 'r') f = file.readlines() newList = [] for line in f: newList.append(line.strip()) print(newList) self.root.ids.newList.text = (newList) if __name__ == '__main__': MyApp().run() RE: How to read text in kivy textinput or Label - joe_momma - Dec-29-2020 to access the input text you can use the textinput id newList => newList.text from kivy.app import App from kivy.lang import Builder from kivy.properties import StringProperty from kivy.uix.textinput import TextInput kv = ''' BoxLayout: orientation: 'vertical' text: newList TextInput: id: newList Button: text: 'click' on_press: app.clicked(newList.text) ''' class MyApp(App): text = StringProperty('-.text') def build(self): return Builder.load_string(kv) def clicked(self,text_): print(text_) if __name__ == '__main__': MyApp().run() |