I am trying to a make a music player using Kivy, which will just have two button; one for play and one for pause. When I trying to bind a function to the buttons, when I press the buttons, I get errors. Upon searching this very own site for this, there was a suggestion to use the partial
function from the functools
library. But even that didn't work. My code is below.
class Layout(FloatLayout):
def __init__(self, **kwargs):
super(Layout, self).__init__(**kwargs)
self.size = Window.size
self.play = Button(text="Play", size_hint=(0.25, 0.25), font_size=36, background_color=color,
pos=(self.size[0]*(3/8), self.size[1]*(4/10)) )
self.pause = Button(text="Pause", size_hint=(0.25, 0.25), font_size=36, background_color=color,
pos=(self.size[0]*(3/8), self.size[1]*(1/10)) )
self.play.bind(on_press=self.play)
self.pause.bind(on_press=self.pause)
self.add_widget(self.play)
self.add_widget(self.pause)
def play(self):
print("PLay")
def pause(self):
print("Pause")
This gave this error
AssertionError: <kivy.uix.button.Button object at 0x000001D1D4792CF0> is not callable
and by using the partial function
self.play.bind(on_press=partial(self.play))
self.pause.bind(on_press=partial(self.pause))
I get served this
TypeError: the first argument must be callable