Using recursion with Kivy event on_complete Animation?

I am trying to animate 10 widgets in sequence, each animation has to start from the previous end. Unfortunately, my solution below runs all the animations in sequence without waiting for anything to finish.

def Animate_Widget(self,index):
    if index < 10:
        anim = Animation(x = self.position[index][0], y = self.position[index][1], d=1)
        anim.bind(on_complete=self.Animate_Widget(index + 1))
        anim.start(self.ids['widget' + str(index)])

def Resize_Layout(self):
    self.Animate_Widget(0)

      

+3


source to share


1 answer


Here:

anim.bind(on_complete=self.Animate_Widget(index + 1))

      

You call your callback immediately. This is because the arguments anim.bind

are evaluated when called. Instead, define another function or lambda to delay the call, which can be called without any arguments:



def callback():
    self.Animate_Widget(index + 1)
anim.bind(on_complete=callback)

      

Or:

anim.bind(on_complete=lambda: self.Animate_Widget(index + 1))

      

+4


source







All Articles