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

Advanced text manipulation


Text is one of the most commonly used contents used in the apps. The recipe will create an app with a label widget where we will use text rendering to make our Hello World.

How to do it…

We are going to use one simple Python files that will just show our Hello World text. To complete the recipe:

  1. Import the usual kivy packages.

  2. Also, import the label package.

  3. Define the e9app class instanced as app.

  4. Define the method build() to the class.

  5. Return the label widget with our Hello World text.

    import kivy
    kivy.require('1.9.0') # Code tested in this version!
    from kivy.app import App
    from kivy.uix.label import Label
    
    class e9App(App):
    
        def build(self):
            return Label(text='Hello [ref=world][color=0000ff]World[/color][/ref]', markup=True, font_size=80, font_name='DroidSans')
    
    if __name__ == '__main__':
        e9App().run()

How it works…

Here is the line:

        return Label(text='Hello [ref=world][color=0000ff]World[/color][/ref]', markup=True, font_size=80, font_name='DroidSans...