Question

I am trying to get the textinput widget to pass text into the callback function that makes a label with the text when called by the printbutton, should be fairly simple when you think about it. But I have a habit of not seeing the wood for the trees. Anyhoo, if anyone can figure this out then code it up :P

import kivy
kivy.require('1.5.1')
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput

class kivyentrywidget(GridLayout):

    def __init__(self, **kwargs):
        super(kivyentrywidget, self).__init__(**kwargs)
        self.cols = 2
        self.add_widget(Label(text='What do you want to print?'))
        self.text_input = TextInput(multiline=False)
        self.add_widget(self.text_input)
        self.printbutton = Button(text='Print')
        self.printbutton.bind(on_press=callback)
        self.add_widget(self.printbutton)

    def callback(self):
        return Label(text=self.text_input.text)



class Firstapp(App):
    def build(self):
        return kivyentrywidget()

if __name__ == '__main__':
    Firstapp().run()
Was it helpful?

Solution

def callback(self,evt=None): #not sure if kivy sends event info so added optional arg just in case
    return self.add_widget(Label(text=self.text_input.text))

maybe ... not overly familiar with kivy but i think that would do it ..

also

self.printbutton.bind(on_press=self.callback)

should fix your other problem

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top