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

Preface

Mobile devices have transformed the way applications are perceived. They have increased in interaction types; the user now expects gestures, multi-touches, animations, responsiveness, virtual keyboards, and magic-pens. Moreover, compatibility has become a must if you want to avoid the barriers imposed by major operating systems. Kivy is an open source Python solution that covers these market needs with an easy-to-learn and rapid development approach. Kivy continues to grow fast and two versions have been released since the first publication of this book in September 2013. Thanks to an enthusiastic community, Kivy is making its way in an extremely competitive territory in which it stands out for offering both a cross-platform and efficient alternative to native development and HTML5.

This book introduces you to the Kivy world, covering a large variety of important topics related to interactive applications and games development. The components presented in this book were selected according to their usefulness for developing state-of-art applications and also for serving as an example of broader Kivy functionalities. Following this approach, the book covers a big part of the Kivy library.

This book provides you with examples to understand their use and how to integrate the three projects that come with this book. The first one, the comic creator, exemplifies how to build a user interface (Chapter 1, GUI Basics – Building an Interface), how to draw vector shapes in the screen (Chapter 2, Graphics – the Canvas), how to bind user interactions with pieces codes (Chapter 3, Widget Events – Binding Actions), and other components related to improving the user experience (Chapter 4, Improving the User Experience). The second project, Invaders Revenge, is an interactive game that introduces you to the use of animations, scheduling of tasks, keyboard events, and multi-touch control (Chapter 5, Invaders Revenge – an Interactive Multi-touch Game). The third project, Kivy Player, teaches how we can control video streams with a modern design and responsive interactions to maximize the use of the screen (Chapter 6, Kivy Player – a TED Video Streamer).

Occasionally, this book explains some technical but important Kivy concepts that are related to the Kivy class structure and implementation, or the order and strategies to draw on the screen. These explanations give the reader some insights into the Kivy internals that will help them solve potential problems when they develop their own projects. Even though they are not necessary for the comprehension of the main topics of this book, they will become important lessons when the reader faces new situations implementing their own applications.

This book grabs the reader's attention by stating interesting programming scenarios. The sections are generally short and straightforward, making the learning process constant. These short sections will also serve as a reference when the reader finishes the book. However, serving as a reference doesn't prevent the text from achieving the main goal, which is teaching bigger projects that connect the small topics. At the end of this book, the reader will feel comfortable to start their own project.

What this book covers

Chapter 1, GUI Basics – Building an Interface, introduces the basic components and layouts of Kivy and how to integrate them through the Kivy Language.

Chapter 2, Graphics – the Canvas, explains the use of the canvas and how to draw vector figures on the screen.

Chapter 3, Widget Events – Binding Actions, teaches how to connect the interactions of the user through the interface with particular code inside the program.

Chapter 4, Improving the User Experience, introduces a collection of useful components to enrich the interaction of the user with the interface.

Chapter 5, Invaders Revenge – an Interactive Multi-touch Game, presents components and strategies to build highly interactive applications.

Chapter 6, Kivy Player – a TED Video Streamer, builds a responsive and professional-looking interface to control a video stream service.

What you need for this book

You need to have some programming experience before starting this book and specifically have a good understanding of some software engineering concepts, particularly inheritance and the difference between classes and instances. You should be already familiar with Python. That said, the code is kept as simple as possible and it avoids the use of very specific Python nuances, so any other developer can follow it. No previous experience of Kivy is required, though some general programming knowledge of event handling, scheduling, and user interfaces would boost your learning. You also need to have Kivy 1.9.0 installed with all its requirements. The installation instructions can be found at http://kivy.org/docs/gettingstarted/installation.html.

Who this book is for

The book aims at developers, specifically Python developers, who want to create UI/UX applications for different platforms. This book will also benefit developers that are seeking for an alternative to HTML5 or native Android/iOS development, looking forward to learn about mobile development and its demands (multi-touch, gestures, and animations), or wishing to improve their understanding of object-oriented topics such as inheritance, classes and instances, and event handling.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "This is the reason we included the on_touch_down event."

A block of code is set as follows:

1. # File name: hello.py
2. import kivy
3. kivy.require('1.9.0')
4. 
5. from kivy.app import App
6. from kivy.uix.button import Label
7. 
8. class HelloApp(App):
9.     def build(self):
10         return Label(text='Hello World!')
11. 
12. if __name__=="__main__":
13.         HelloApp().run()

The numeration restarts at the beginning of each chapter providing a unique identifier to each line code. Code from previous chapter will never be referenced, instead it will be copied again if needed. When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold, for example, line 10.

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "We need an alternate way to stop the video (different from the Stop button)."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.