0

Using qpython and kivy on my android phone, I'm trying to write a program that inputs some text, processes it and shows the output.

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput

class TestApp(App):
    def build(self)
        r = TextInput(multiline=False).text
        y = self.dosomething(r)
        return Button(text = y)

    def dosomething(self, x):
        y = x + ' something'
        return y

TestApp().run

This fails - when I push run it doesn't ask for input and just display 'something'.

How do I fix this so I can actually get some text input from the user?

EDIT replace build with:

def build(self):
   def cb(instance, value):
      print(value)
   r = TextInput(focus=True, multiline=False)
   r.bind(text=cb)
   return r
foosion
  • 7,619
  • 25
  • 65
  • 102
  • I think you should read read the kivy documentation to understand how it works. You could start with the [pong tutorial](http://kivy.org/docs/tutorials/pong.html). – inclement Nov 01 '15 at 16:37
  • @inclement I read the pong tutorial. The only thing I can think of is that textinput() is not waiting for input and just returning an empty string; it needs a callback or some such triggered by hitting enter. I don't know how to do this. – foosion Nov 01 '15 at 16:47
  • You create a TextInput, access its text property (which is just `''`, the empty string, because it hasn't done anything), then display a Button containing the result of this. That's why you get the given result. To have it work as you expect, you need to display the TextInput and bind some logic to when it is interacted with. – inclement Nov 01 '15 at 17:08
  • ok, so the question is how to display it. See edit. Why doesn't this display? – foosion Nov 01 '15 at 17:18
  • Because you need `TestApp().run()`, not `TestApp().run`, but you have the latter. It seems there's a bug though that you possibly can't type in the textinput if you create it with focus=True, presumably because it's instantiated before the keyboard stuff is initialised. If you see the same behaviour, you could report a bug on github about it. – inclement Nov 01 '15 at 17:30
  • I was running with TestApp.run(), but didn't copy the last few characters here. I eliminated focus=True and can now type - a keyboard comes up after touching the screen. However, the print statement does not produce visible output. – foosion Nov 01 '15 at 18:14
  • If you're runing on android, there's nowhere for the output to be displayed, so it's redirected to the adb logcat stream which you can access with the android development tools. – inclement Nov 01 '15 at 20:05
  • In that case, I suppose I'll just go back to dialogGetInput and console output. The only reason to use kivy was easier/prettier input and output. – foosion Nov 01 '15 at 20:25

0 Answers0