I am trying to learn how to create application in Kivy and I have problem with sending argument to the function. I want to send text from input to the function and print it. Can somebody tell me how can I do it ?
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
class TutorialApp(App):
def gratulation(self, *args):
print args
def build(self):
boxLayout = BoxLayout(spacing=10,orientation='vertical')
g = TextInput(text='Enter gratulation',
multiline=False,
font_size=20,
height=100)
button = Button(text='Send')
button.bind(on_press=self.gratulation)
boxLayout.add_widget(g)
boxLayout.add_widget(button)
return boxLayout
if __name__ == "__main__":
TutorialApp().run()
Yo must get the text from "g" and then send it to the button callback, there is 2 ways of doing this, by a lambda function, or calling your class method aplying to it.
Lambda Version:
The partial version:
One way to do it:
Hope it helps!