BehradX
BehradX

Reputation: 57

Making a flashing image

I've been trying to make a flashing picture in kivy but since loops and time.sleep() can't be used in kivy, I don't know how to deal with it.

I've looked for similar projects and samples but I couldn't find any. I've found some code about a flashing text (like one below), but it gives an error. (btw due to some limitations, I can't use the .kv format.)

anim  = Animation(alpha=0, duration=0.1) + Animation(alpha=0, duration=1)
anim += Animation(alpha=1, duration=0.1) + Animation(alpha=1, duration=1)
anim.repeat = True
anim.start(widget)

the error that I get:

original_value = getattr(widget, key)
 AttributeError: 'Image' object has no attribute 'alpha'

Upvotes: 3

Views: 190

Answers (1)

eyllanesc
eyllanesc

Reputation: 243955

Image does not have the alpha property so you get that error, if you want to modify the alpha you must use the color property.

anim = Animation(color=[1, 1, 1, 0], duration=0.1)
anim += Animation(color=[1, 1, 1, 0], duration=1)
anim += Animation(color=[1, 1, 1, 1], duration=0.1)
anim += Animation(color=[1, 1, 1, 1], duration=1)
anim.repeat = True
anim.start(widget)

Upvotes: 3

Related Questions