kivy - save user input into a python list
<p>I`m having some difficulties understanding the interrelation between kivy and python.</p>

<p>I`m trying to do something super simple, as a first step, and it would be great if anybody could show an example:
How can I store input data into a python list once the user feeds-in data and press "enter"?
Thanks</p>

<p>An example of this. User can input 3 things and they get stored in an array. If you want the user to input one thing and store it in an array you will have to split the input.</p>

<pre><code>result = []
for i in range(3):
    answer = input()
    result.append(answer)

print(result)
</code></pre>

<p>NOTE: <code>input()</code> is <code>raw_input()</code> in python2.x</p>

<p>In <code>kivy</code>:</p>

<pre><code>from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput


class Screen(GridLayout):
    def __init__(self, **kwargs):
        super(Screen, self).__init__(**kwargs)
        self.input = TextInput(multiline=False)
        self.add_widget(self.input)
        self.input.bind(on_text_validate=self.print_input)
    def print_input(self, value):
        print(value.text)


class MyApp(App):

    def build(self):
        return Screen()


if __name__ == '__main__':
    MyApp().run()
</code></pre>

<p>This simple script will give you an input box and when you press enter it will print its text to terminal. You can easily store it in a list if you wish. </p>

python kivy kivy-language