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:
In the KV file, define a label using the following code:
<MyW>: Label: id: label1 ...