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

Binding events in the Kivy language


So far, we have been handling events in two ways: overridding an event method (for example, on_touch_event) and binding a personalize method to a related event method (for example, ds.bind(on_touch_move=self.update_figure)). In this section, we will discuss a different way, that is, binding events in the Kivy language. Potentially, we could have done this since the beginning of this chapter when we started working with DraggableWidget but there is a difference. If we use the Kivy language, we can easily add the event to a specific instance and not to all the instances of the same class. In this sense, it resembles dinamically binding an instance to its callback with the bind method.

We are going to concentrate on new events specific to Button and ToggleButton. The following is the code for generaloption.kv:

193. # File name: generaloptions.kv
194. #:import generaloptions generaloptions
195. <GeneralOptions>:
196.    orientation: 'horizontal'
197. ...