Quick search

Animation

Animation and AnimationTransition are used to animate Widget properties. You must specify (minimum) a property name and target value. To use 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 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 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 position to (80, 10) over 1 second, while in parallel animating the first half of size=(800, 800):

anim = Animation(pos=(80, 10))
anim &= Animation(size=(800, 800), duration=2.)
anim.start(widget)
class kivy.animation.Animation(**kw)

Bases: kivy.event.EventDispatcher

Create an animation definition that can be used to animate a Widget

Parameters :
duration or d: float, default 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. Default 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.

animated_properties

Return the properties used to animate

cancel(widget)

Cancel the animation previously applied on 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)

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)

Even if an animation is running, remove a property. It will not be animated further. If it was the only/last property being animated on. the widget, the animation will be canceled (see cancel)

New in version 1.4.0.

duration

Return the duration of the animation

start(widget)

Start the animation on a widget

stop(widget)

Stop the animation previously applied on a widget, triggering on_complete event

static stop_all(widget, *largs)

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')
stop_property(widget, prop)

Even if an animation is running, remove a property. It will not be animated further. If it was the only/last property being animated on. the widget, the animation will be stopped (see stop)

transition

Return the transition of the animation

class kivy.animation.AnimationTransition

Bases: object

Collection of animation function, to be used with Animation object. Easing Functions ported into Kivy from Clutter Project http://www.clutter-project.org/docs/clutter/stable/ClutterAlpha.html

progress parameter in each animation functions is between 0-1 range.

static in_back(progress)
_images/anim_in_back.png
static in_bounce(progress)
_images/anim_in_bounce.png
static in_circ(progress)
_images/anim_in_circ.png
static in_cubic(progress)
_images/anim_in_cubic.png
static in_elastic(progress)
_images/anim_in_elastic.png
static in_expo(progress)
_images/anim_in_expo.png
static in_out_back(progress)
_images/anim_in_out_back.png
static in_out_bounce(progress)
_images/anim_in_out_bounce.png
static in_out_circ(progress)
_images/anim_in_out_circ.png
static in_out_cubic(progress)
_images/anim_in_out_cubic.png
static in_out_elastic(progress)
_images/anim_in_out_elastic.png
static in_out_expo(progress)
_images/anim_in_out_expo.png
static in_out_quad(progress)
_images/anim_in_out_quad.png
static in_out_quart(progress)
_images/anim_in_out_quart.png
static in_out_quint(progress)
_images/anim_in_out_quint.png
static in_out_sine(progress)
_images/anim_in_out_sine.png
static in_quad(progress)
_images/anim_in_quad.png
static in_quart(progress)
_images/anim_in_quart.png
static in_quint(progress)
_images/anim_in_quint.png
static in_sine(progress)
_images/anim_in_sine.png
static linear(progress)
_images/anim_linear.png
static out_back(progress)
_images/anim_out_back.png
static out_bounce(progress)
_images/anim_out_bounce.png
static out_circ(progress)
_images/anim_out_circ.png
static out_cubic(progress)
_images/anim_out_cubic.png
static out_elastic(progress)
_images/anim_out_elastic.png
static out_expo(progress)
_images/anim_out_expo.png
static out_quad(progress)
_images/anim_out_quad.png
static out_quart(progress)
_images/anim_out_quart.png
static out_quint(progress)
_images/anim_out_quint.png
static out_sine(progress)
_images/anim_out_sine.png