Kivy – Interactive Applications in Python

Author: Roberto Ulloa
Publisher: Packt
Pages: 138
ISBN: 978-1783281596
Audience: Intermediate
Rating: 3
Reviewer: Mike Driscoll

This is currently the only book about Kivy, a Python GUI toolkit.

Kivy is a cross-platform GUI toolkit that will run on Linux, Windows, and OS X as well as Android and iOS. In fact, the people behind Kivy emphasize that this is aimed primarily at mobile programming. Kivy supports multitouch and has a very active group of programmers. You can read more about Kivy on the project’s home page and for news of the latest version see our recent report Kivy 1.8 Now With Python 3.x Support.

For this review I read the PDF version.

The book is split into five chapters. The first four chapters cover the comic creator project, which is about creating shapes and drawing with Kivy. The reader is supposed to learn GUI basics (Chapter 1), layouts (Chapter 1), how to use the canvas object (Chapter 2), widget events (Chapter 3), improving the user experience (Chapter 4) and the last chapter covers the second and last project, which is a clone of Space Invaders.

 

Banner

 

The Kivy toolkit supports two languages. You can write your programs entirely in Python or you can do a mixture of Python plus the Kv language. The Kv language looks kind of like CSS+Python and it has indentation requirements similar to Python (i.e. each block must be indented 4 spaces). The first example of using the Kv language is not properly indented in the book. The author never mentions the need to indent the Kv code four spaces, so it took me a while to figure out why the code didn’t work. You will find that almost every example of Kv code in the book will not work if you copy it. Some of the Python code has indentation issues as well. Packt hires a lot of authors whose primary language is not English. This book has lots of examples of sentences that are difficult to read or just don’t make sense. Let’s look at each chapter.

The first chapter covers how to launch a Kivy application, how to add a widget or two, the properties / variables of widgets, the various coordinate systems of Kivy and layouts. The first couple of sections are pretty straight forward. The coordinates section is muddled and takes much re-reading to understand. I only understood parts of the layout section. Layouts in Kivy are analogous to sizers in wxPython. They help control how widgets are positioned dynamically when the user changes the window size.

Chapter 2 digs into Kivy’s canvas object. It covers how to draw shapes, insert images, how to use colors, scaling and translating. There is also information in this chapter about storing/retrieving the current coordinate space context. The image and color section was the highlight for me. The rest, not so much.

 

 

In Chapter 3, we learn about event binding in Kivy. You get to learn how to override, bind, unbind, and create Kivy events. You’ll also learn about how to use properties to keep the UI up-to-date. The chapter purports to explain several other topics as well. I’m not sure I understood the author’s reasoning for constantly binding events and then unbinding them, but at least now I know how to do it. There’s a section about translating relative and absolute coordinates between widgets, the widget’s parent and the window itself. That section is confusing, but interesting too.

For Chapter 4, introduces screen managers. This concept makes it easy to switch screens, which is kind of like swapping panels in wxPython except that it’s built into Kivy. It also talks about a Color Control widget, creating and saving gestures, and multitouch for drag, rotate and scaling. The gesture portion of the chapter was intriguing, although I didn’t think it was explained in enough detail. Kivy actually has classes built into it specifically for saving and retrieving custom gestures. I wish this section mentioned how accurate Kivy is at recognizing gestures, but it doesn’t.

Chapter 5 is all about the clone of Space Invaders. This chapter is only 20 pages, so I don’t think it gives enough detail about how everything works. It felt rushed to me. On the other hand, I enjoy learning how to create games, so I’ll give the author props for that. And there was a lot of cool information in the chapter. You just have to spend most of it deciphering the code though.

In the end, I was left wanting to know more about Kivy. I found Kivy’s documentation much more helpful than the book, but the book at least had some interesting ideas in it. I think that’s its most redeeming value. It makes you want to learn Kivy so you can improve the two projects in the book and make your own. One key topic that I think is sorely missing is the actual distribution of the projects to one or both of the mobile platforms as well as how to go about testing on those platforms. Does Kivy work in an Android or iOS emulator? Does Kivy have more than 7 or 8 widgets? These questions aren’t answered.

If you can get the book cheap, I would say go for it. Otherwise, stick with the Kivy documentation and demo programs.

Banner


Beautiful C++

Author: J. Guy Davidson and Kate Gregory
Publisher: Addison-Wesley Professional
Date: December 2021
Pages: 352
ISBN: 978-0137647842
Print: 0137647840
Kindle: B09HTH1X38
Audience: C++ developers
Rating: 5
Reviewer: Mike James
Can C++ be beautiful?



Data Structures & Algorithms in Python

Author: Dr. John Canning, Alan Broder and Robert Lafore
Publisher: Addison-Wesley
Date: October 2022
Pages: 928
ISBN:978-0134855684
Print: 013485568X
Kindle: B0B1WJF1K9
Audience: Python developers
Rating: 4
Reviewer: Mike James
Data structures in Python - a good idea!


More Reviews