Book Image

Kivy: Interactive Applications in Python

By : Roberto Ulloa
4 (1)
Book Image

Kivy: Interactive Applications in Python

4 (1)
By: Roberto Ulloa

Overview of this book

Mobiles and tablets have brought with them a dramatic change in the utility of applications. Compatibility has become essential, and this has increased the kind of interaction that users expect: gestures, multi-touches, animations, and magic pens. Kivy is an open source Python solution that covers these market needs with an easy-to-learn and rapid development approach. Kivy is growing fast and gaining attention as an alternative to the established developing platforms. Kivy: Interactive Applications in Python quickly introduces you to the Kivy development methodology. You will learn some examples of how to use many of the Kivy components, as well as understand how to integrate and combine them into big projects. This book serves as a reference guide and is organized in such a way that once finished, you will have already completed your first project. You will start by learning the Kivy Language for building User Interfaces (UI) and vector figures. We then proceed to the uses of Kivy events and properties to glue the UI with the application logic. You then go on to build an entire User Interface (UI) starting from a hand-made sketch. Furthermore, you will go on to understand how to use the canvas and drawing instructions to create different types of geometrical figures. Finally, you will be introduced to a big set of interactive and smooth features: transformations (scale, rotate, and translate), gestures, animations, scheduling tasks, and multi-touch elements. Kivy: Interactive Applications in Python expands your knowledge by introducing various components that improve the User Experience (UX). Towards the end of the book, you will be confident to utilize Kivy components and strategies to start any application or game you have in mind.
Table of Contents (13 chapters)
Kivy: Interactive Applications in Python
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Chapter 1. GUI Basics – Building an Interface

Kivy emerges as a successor of PyMT (a library for multitouch applications) with a simple but ambitious goal in mind — same code for every commonplace platform: Linux / Windows / Mac OS X / Macosx / Android / iOS (Mathieu Virbel, http://txzone.net/2011/01/kivy-next-pymt-on-android-step-1-done/). This support is being extended to Raspberry Pi thanks to a founding campaign started by Mathieu Virbel, the creator of Kivy. Kivy was introduced in the EuroPython 2011, as a Python framework designed for creating natural user interfaces.

So, let's start creating user interfaces using one of its fun and powerful components, the Kivy language (.kv). The Kivy language helps us to separate the logic from the presentation. This is a fundamental engineering concept that helps to keep an easy and intuitive code. Nonetheless, it is possible to build a Kivy application using pure Python and Kivy as a library. We will also learn those concepts in later chapters because they allow us to modify interfaces dynamically.

This chapter covers all the basics for building a graphical user interface (GUI) in Kivy. Afterwards, you will be able to build practically any GUI you have in your mind, and even make them responsive to the size of window! The following is a list of all the skills that you're about to learn:

  • Launching a Kivy application

  • The Kivy language

  • Creating and using widgets (GUI components)

  • Basic properties and variables of the widgets

  • Fixed, proportional, absolute, and relative coordinates

  • Organizing GUIs through layouts

  • Tips for achieving responsive GUIs

Apart from Python, this chapter requires some knowledge about Object-Oriented Programming (http://en.wikipedia.org/wiki/Object-oriented_programming) concepts. In particular, inheritance (http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)) and the difference between instances (http://en.wikipedia.org/wiki/Instance_(computer_science)) and classes (http://en.wikipedia.org/wiki/Class_(computer_science)) will be assumed. Before starting, you will need to install Kivy (The instructions can be found in http://kivy.org/docs/installation/installation.html). The book examples were tested on Kivy 1.7.0 but a more recent version should work as well.

At the end of this chapter, we will be able to build a GUI starting from a pencil and paper sketch. We will introduce the main project of the book — the Comic Creator, and implement the main structure of the GUI.