Python Forum
How to read text in kivy textinput or Label
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to read text in kivy textinput or Label
#1
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()
buran write Dec-27-2020, 04:41 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 4,813 Jun-26-2022, 06:26 PM
Last Post: menator01
  update text variable on label with keypress knoxvilles_joker 3 4,886 Apr-17-2021, 11:21 PM
Last Post: knoxvilles_joker
  [Kivy] Kivy text label won't shows up! AVD_01 1 2,918 Jun-21-2020, 04:01 PM
Last Post: AVD_01
  [Tkinter] Python 3 change label text gw1500se 6 4,670 May-08-2020, 05:47 PM
Last Post: deanhystad
  [Turtle] numinput and textinput do not work fgarciamoran 1 3,150 Apr-28-2020, 08:44 PM
Last Post: deanhystad
  [Tkinter] how to update label text from list Roshan 8 5,441 Apr-25-2020, 08:04 AM
Last Post: Roshan
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 13,744 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  [Tkinter] Label, align imported text from pandas kundrius 2 4,201 Dec-11-2019, 08:26 AM
Last Post: kundrius
  Make Label Text background (default color) transparent using tkinter in python barry76 1 23,709 Nov-28-2019, 10:19 AM
Last Post: Larz60+
  Update a label text from subprocess jim53 3 4,314 Aug-19-2019, 08:21 PM
Last Post: Denni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020