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

Using BoxLayout


Now, we are going to introduce another layout widget named BoxLayout. Its name is a reference to the heap boxes where the boxes are the child widgets. To illustrate this, we will make a vertical heap of three buttons in this recipe.

Getting ready

You should be familiar with the widget tree abstraction, and it is important to check the recipes about the tree in this chapter.

How to do it…

We will need a KV file to set BoxLayout and a Python file to add the BoxLayout widget to our app. Follow the next steps:

  1. In the KV file, define a BoxLayout widget and set the size_hint and orientation properties.

  2. As children of the BoxLayout:

    <MyW>:
        BoxLayout:
            size_hint: 0.5,0.5
            orientation: 'vertical'
            Button:
                id: label1
                text: 'B1'
            Button:
                id: label2
                text: 'B2'
            Button:
                id: label3
                text: 'B3'
  3. In the Python file, import FloatLayout.

  4. As shown here, define the class for the rule in...