Is there a way to get a fade-in/-out animation on a canvas rectangle background in kivy? I tried it by using the Clock.schedule_interval()
function. But several problems occured concerning concurrency and data raise.
One of my tries looks as follows:
def calendarClicked(self, *args):
self.alpha = 1.0
self.alphaDelta = 0.01
self.root.canvas.add(Color(1,0,0,self.alpha))
self.root.canvas.add(Rectangle(size=self.root.size))
def fadeIn(self, dt):
self.alpha -= self.alphaDelta
self.root.canvas.add(Color(1,0,0,self.alpha))
self.root.canvas.add(Rectangle(size=self.root.size))
return self.alpha >= 0.5
Clock.schedule_interval(partial(fadeIn, self), 0.1)
Another idea was to use the kivy.animation
. But I coudn't find a way to edit the color instead of the position of an object/widget.
Thanks in advance!
You can use an
Animation
on canvas instructions just like you would a widget. The problem is that you're not modifying the canvas instructions at all, you just keep adding more and more canvas instructions. You need to add the instructions one time only, then update the values viaAnimation
.