Traversing the tree

There are situations when you need to go through the app's widget tree. This recipe will use a tap to add new buttons to the root widgets and double tap to print the children of the root widget in the console. Again, triple tap will clean the widgets of our app.

Getting ready

The code for this recipe is similar to the previous recipe, so you can refer to them and apply the same to this recipe.

How to do it…

For this recipe, follow the next steps:

  1. In the KV file, define a label using the following code:
    <MyW>:
        Label:
            id: label1
            pos: 200,200
            text: 'Hello'
    
  2. In the Python file, create the on_touch_down() method to add a button every time that a touch is performed.
  3. Inside the same method, when double tap is detected, traverse the children ...

Get Kivy Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.