Bind a function to a Button

30 views
Skip to first unread message

Amir Teymuri

unread,
Aug 23, 2016, 12:05:37 PM8/23/16
to Kivy users support
Why is the following code running into trouble? I want to bind the function callBack to the button, but i get:

TypeError: callBack() takes exactly 1 argument (2 given)

import pyo
import time
from kivy.app import App
from kivy.uix.button import Button

class MyApp(App):

        def __init__(self):
                super(MyApp, self).__init__()
                self.button = Button(text = "B",
                                     font_size = 50)
                self.button.bind(on_press = self.callBack)

        def callBack(self):
                print "call back called."
                
        def build(self):
                return self.button





if __name__ == "__main__":
        MyApp().run()



Alexander Taylor

unread,
Aug 23, 2016, 8:32:57 PM8/23/16
to Kivy users support
The on_press event automatically passes an argument (the object instance) to the function that is called. Just make your callBack accept this (extra) argument and it will be fine.
Reply all
Reply to author
Forward
0 new messages