Book Image

Kivy - Interactive Applications and Games in Python

By : Roberto Ulloa
Book Image

Kivy - Interactive Applications and Games in Python

By: Roberto Ulloa

Overview of this book

Table of Contents (13 chapters)
Kivy – Interactive Applications and Games in Python Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating your own events – the magical properties


This section covers the use of the Kivy properties. A Kivy property triggers an event every time we modify it. There are different types of properties, from the simple NumericProperty or StringProperty to much more complex versions such as ListProperty, DictProperty, or ObjectProperty. For example, if we define a StringProperty called text, then an on_text event is going to be triggered each time the text is modified.

Note

Once we define a Kivy property, Kivy internally creates an event associated with that property. The property event is referenced adding the prefix on_ to the name of the property. For example, the on_translation method (line 246) is associated with ListProperty in line 219 called translation.

All the properties work in the same way. For example, the state property that we used in the ToogleButton class is actually a property that creates the on_state event. We already used this event in line 206. We define the property and...