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

Organizing with layouts


Sometimes, it is quite tedious to establish each and every position for all the widgets in our app. There is a special kind of widget, the layouts widget, that makes things easy for us. In this recipe, we will review how to work with the size and position hints that allows us to organize widgets inside this new kind of widget.

Getting ready

A quick check of the recipe Designing with the Kv language in Chapter 1, Kivy and the Kv language could be important to go deeper in this recipe.

How to do it…

To complete the task, perform the following steps:

  1. In the KV file, define two buttons and assign the size_hint and pos_hint properties as follows:

    <MyW1>:
        Button:
            id: label1
            size_hint: .2, .2
            pos_hint: {'center_x':.5, 'center_y': .5}
            text: 'B1'
        Button:
            id: label2
            size_hint: .1, .1
            pos_hint: {'center_x':.1, 'center_y': .1}
            text: 'B2'
    
  2. In the Python file, import the FloatLayout.

  3. Define the class for the...