EventsΒΆ

Events

Kivy is mostly event-based, that’s mean the flow of the program is determined by events.

Clock events

../_images/gs-events-clock.png

The Clock object allows you to schedule a function call in the future, as a one-time event with schedule_once(), or as a repetitive event with schedule_interval().

You can also create Triggered events with create_trigger(), multiple call to a trigger will schedule a function call only once.

Input events

../_images/gs-events-input.png

All the mouses click, touchs, scroll wheel are part of the MotionEvent, extended by Input Postprocessing, dispatched through the on_motion in Window, then in the on_touch_down(), on_touch_move(), on_touch_up() in Widget

For an in-depth explaination, have a look at Input management.

Class events

../_images/gs-events-class.png

Our base class EventDispatcher, used by Widget, use the power of ours Properties for dispatching changes. IE, when a widget changes its position or size, an event is fired.

In addition, you have the possibility to create your own event using register_event_type(), as the on_press/on_release in Button.

Another thing to note is that if you override an event, you become responsible for implementing all its behaviour previously handled by the base class. The easiest way to do this is to call super():

def on_touch_down(self, touch):
    if super(OurClassName, self).on_touch_down(touch):
        return True
    if not self.collide_point(touch.x, touch.y):
        return False
    print 'you touched me!'
    return True

Get more familiar with events by reading the Events documentation.