Python Forum

Full Version: How to read text in kivy textinput or Label
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
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()