Table Of Contents
Animation¶
Animation and AnimationTransition are used to animate Widget properties. You must specify at least a property name and target value. To use an Animation, follow these steps:
- Setup an Animation object
- Use the Animation object on a Widget
Simple animation¶
To animate a Widget’s x or y position, simply specify the target x/y values where you want the widget positioned at the end of the animation:
anim = Animation(x=100, y=100)
anim.start(widget)
The animation will last for 1 second unless duration is specified. When anim.start() is called, the Widget will move smoothly from the current x/y position to (100, 100).
Multiple properties and transitions¶
You can animate multiple properties and use built-in or custom transition functions using transition (or the t= shortcut). For example, to animate the position and size using the ‘in_quad’ transition:
anim = Animation(x=50, size=(80, 80), t='in_quad')
anim.start(widget)
Note that the t= parameter can be the string name of a method in the AnimationTransition class or your own animation function.
Sequential animation¶
To join animations sequentially, use the ‘+’ operator. The following example will animate to x=50 over 1 second, then animate the size to (80, 80) over the next two seconds:
anim = Animation(x=50) + Animation(size=(80, 80), duration=2.)
anim.start(widget)
Parallel animation¶
To join animations in parallel, use the ‘&’ operator. The following example will animate the position to (80, 10) over 1 second, whilst in parallel animating the size to (800, 800):
anim = Animation(pos=(80, 10))
anim &= Animation(size=(800, 800), duration=2.)
anim.start(widget)
Repeating animation¶
New in version 1.8.0.
Note
This is currently only implemented for ‘Sequence’ animations.
To set an animation to repeat, simply set the Sequence.repeat property to True:
anim = Animation(...) + Animation(...)
anim.repeat = True
anim.start(widget)
For flow control of animations such as stopping and cancelling, use the methods already in place in the animation module.
- class kivy.animation.Animation(**kw)[source]¶
Bases: kivy.event.EventDispatcher
Create an animation definition that can be used to animate a Widget.
Parameters: - duration or d: float, defaults to 1.
Duration of the animation, in seconds.
- transition or t: str or func
Transition function for animate properties. It can be the name of a method from AnimationTransition.
- step or s: float
Step in milliseconds of the animation. Defaults to 1 / 60.
Events: - on_start: widget
Fired when the animation is started on a widget.
- on_complete: widget
Fired when the animation is completed or stopped on a widget.
- on_progress: widget, progression
Fired when the progression of the animation is changing.
Changed in version 1.4.0: Added s/step parameter.
- cancel(widget)[source]¶
Cancel the animation previously applied to a widget. Same effect as stop, except the on_complete event will not be triggered!
New in version 1.4.0.
- static cancel_all(widget, *largs)[source]¶
Cancel all animations that concern a specific widget / list of properties. See cancel.
Example:
anim = Animation(x=50) anim.start(widget) # and later Animation.cancel_all(widget, 'x')
New in version 1.4.0.
- cancel_property(widget, prop)[source]¶
Even if an animation is running, remove a property. It will not be animated further. If it was the only/last property being animated, the animation will be canceled (see cancel)
New in version 1.4.0.
- have_properties_to_animate(widget)[source]¶
Return True if a widget still has properties to animate.
New in version 1.8.0.
- stop(widget)[source]¶
Stop the animation previously applied to a widget, triggering the on_complete event.
- static stop_all(widget, *largs)[source]¶
Stop all animations that concern a specific widget / list of properties.
Example:
anim = Animation(x=50) anim.start(widget) # and later Animation.stop_all(widget, 'x')
- class kivy.animation.AnimationTransition[source]¶
Bases: object
Collection of animation functions to be used with the Animation object. Easing Functions ported to Kivy from the Clutter Project http://www.clutter-project.org/docs/clutter/stable/ClutterAlpha.html
The progress parameter in each animation function is in the range 0-1.