newbie in programming, and i cant seem to count how many times the animation has been executed, i wanted to be able to close it after a specific number of times the animation has been executed/completed.

class MainApp(App): count = 0

def build(self):
    return Builder.load_file("kv_ellipse.kv")

def on_start(self):
    print("start")
    Clock.schedule_interval(self.animate_the_widget, 1.1)

def animate_the_widget(self, widget, *args):

    self.count + 1
    print("animate")
    widget = self.root.ids.the_blinking_button
    anim = Animation(animated_color=(0, 0, .5, 0), blink_size=200)
    anim.bind(on_complete = self.counter)
    anim.start(widget)

def reset(self, *args):
    print("reset")
    widget = args[1]
    widget.animated_color = (.1, .4, .4, 1)
    widget.blink_size = 5

def counter(self, *args):
    self.reset(self.count + 1)
    print('counter', self.count)

MainApp().run()

1 Answers

0
el3ien On Best Solutions

First set your clock schedule as a class attribute, so you can unschedule it later.

self.clock = Clock.schedule_interval(self.animate_the_widget, 1.1)

Then, when you increment a counter in python do like this.

self.count += 1

Then later you can check for this counter and unschedule.

if self.count > 9:
    Clock.unschedule(self.clock)
    # and / or do whatever you need here. 
    #If it's just to stop the app, exit() is enough.
    exit()