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
  update text variable on label with keypress knoxvilles_joker 3 912 Apr-17-2021, 11:21 PM
Last Post: knoxvilles_joker
  [Kivy] Kivy text label won't shows up! AVD_01 1 1,305 Jun-21-2020, 04:01 PM
Last Post: AVD_01
  [Tkinter] Python 3 change label text gw1500se 6 1,877 May-08-2020, 05:47 PM
Last Post: deanhystad
  [Turtle] numinput and textinput do not work fgarciamoran 1 1,108 Apr-28-2020, 08:44 PM
Last Post: deanhystad
  [Tkinter] how to update label text from list Roshan 8 1,925 Apr-25-2020, 08:04 AM
Last Post: Roshan
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 6,809 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  [Tkinter] Label, align imported text from pandas kundrius 2 2,174 Dec-11-2019, 08:26 AM
Last Post: kundrius
  Make Label Text background (default color) transparent using tkinter in python barry76 1 14,412 Nov-28-2019, 10:19 AM
Last Post: Larz60+
  Update a label text from subprocess jim53 3 2,159 Aug-19-2019, 08:21 PM
Last Post: Denni
  Unable to update or refresh label text in tkinter jenkins43 3 3,814 Jul-24-2019, 02:09 PM
Last Post: Friend

Forum Jump:

User Panel Messages

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