Home > Back-end >  Appednding the text on a TextInput field to list in kivy for manipulation
Appednding the text on a TextInput field to list in kivy for manipulation

Time:07-27

  • Appending TextInput objects to a list.

I created a screen with buttons 0 - 9 with a single TextInput field that displays the numbers on_clicking them, along with an ENTER button.

  • Assuming I clicked 5 & 6 , 56 will be displayed on the TextInput field.

  • what I'm trying to achieve is: on_clicking the ENTER button, the number displaying on the TextInput field should be added to a list for manipulation.

CodePudding user response:

You can bind a functiun to a TextInput, by using on_text_validate. If you use this, a certain function will run, when the user hits Enter. Here is how it should look in the kv file:

TextInput:
    id: mytext
    on_text_validate: root.add_to_list()

And then in the py file in the class:

class YourApp(FloatLayout): #FloatLayout is just an example, you can use this method with all layouts
    list = []
    def add_to_list(self):
        content_of_textfield = self.ids.mytext.text
#saving the content of the textfield into a variable
        list.append(content_of_textfield) #adding the variable to the list
  • Related