Book Image

Kivy Cookbook

By : Hugo Solis
Book Image

Kivy Cookbook

By: Hugo Solis

Overview of this book

Table of Contents (16 chapters)
Kivy Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Manipulating the widget tree


Now, we want to give more flexibility to our apps. There are situations when we have to add or remove widgets at the execution time, which results in a direct manipulation of the app's widget tree. In this recipe, we will develop an app that will add buttons with a click and will remove all widgets with a triple-click. We will use the double-click to remove a specific widget.

Getting ready

We will use the widget tree in this recipe, so it could be useful to review the recipe Referencing widgets in Chapter 1, Kivy and the Kv language. Also, we will be working with multitapping, so you either need to have your basics clear or refer to Detecting multitapping recipe from Chapter 2, Input, Motion, and Touch.

How to do it…

We will use two files: the KV file with the widgets and a Python file with the instructions to manipulate the widget tree. Follow the next steps:

  1. In the KV file, define a label using the following code:

    <MyW>:
        Label:
            id: label1
        ...