I was trying to understand the kivy library in python. Below is the complete code.
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
class MyGrid(GridLayout):
def __init__(self, **kwargs):
super(MyGrid, self).__init__(**kwargs)
self.cols = 1
self.inside = GridLayout()
self.inside.cols = 2
self.inside.name = TextInput(multiline=False)
self.inside.add_widget(self.inside.name)
self.inside.add_widget(Label(text="Name: "))
self.inside.name = TextInput(multiline=False)
self.inside.add_widget(self.inside.name)
self.inside.add_widget(Label(text="Email: "))
self.inside.name = TextInput(multiline=False)
self.inside.add_widget(self.inside.name)
self.inside.add_widget(Label(text="Phno: "))
self.add_widget(self.inside)
self.submit = Button(text="Submit", font_size=40)
self.submit.bind(on_press=self.pressed)
self.add_widget(self.submit)
def pressed(self, instance):
print("pressed")
class MyApp(App):
def build(self):
return MyGrid()
if __name__ == "__main__":
MyApp().run()
Here, while in MyGrid class, under init method, when I try to bind the submit button(self.submit.bind) with the pressed method, the argument with on_press doesn't include parentheses.
self.submit.bind(on_press=self.pressed)
Why does it work? Is it because it's a python convention to not include parentheses while passing it to a method?
And what is the use of the instance argument in the pressed method?