Skip to Content
Creating Apps in Kivy
book

Creating Apps in Kivy

by Dusty Phillips
April 2014
Beginner to intermediate content levelBeginner to intermediate
188 pages
4h 17m
English
O'Reilly Media, Inc.
Content preview from Creating Apps in Kivy

Chapter 7. Gestures

Kivy was designed from the ground up with fingers, rather than pointing devices, in mind as a primary method of input. You haven’t had much direct interaction with input devices in this book; instead, we’ve focused on touch events that are built into widgets supplied with Kivy. Buttons can be pressed, inputs can have text entered into them, and ListViews can be scrolled with a gesture.

In this chapter, you’ll delve a bit deeper into Kivy’s event system and add a few basic gestures to the app. The gestures will be swipe left and swipe right on the current weather and forecast widgets, which will switch to the other widget. The swipe down gesture will be used to refresh the weather. This is a fairly standard interaction feature in mobile computing.

The Forecast Tab

First, take some time to implement the forecast widget, so you have something to use gestures to switch between. As in Chapter 6, this should be old hat for you, so I’m just going to summarize the changes. Then I can focus on giving you new and interesting content! I recommend you try to implement these steps before referring to the example code.

  1. Create a mockup of how you would like the forecast to look. Bear in mind that your widget has to fit on a narrow mobile screen. See Figure 7-1.
  2. Add a ForecastLabel class to weather.kv to render individual forecast data. Put an icon, conditions, and temperature min and max on it. See Example 7-1.
  3. Add a Forecast class extending BoxLayout to main.py and weather.kv ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Kivy - Interactive Applications and Games in Python

Kivy - Interactive Applications and Games in Python

Roberto Ulloa
Kivy Cookbook

Kivy Cookbook

Hugo Solis
Kivy Blueprints

Kivy Blueprints

Mark Vasilkov

Publisher Resources

ISBN: 9781491947333ErrataSupplemental Content