Kivy Basics

Kivy Video Overviews

// Basic Kivy Code (main.py)
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

class Interface(BoxLayout):
    pass
    
class LayoutApp(App):
    pass
    
LayoutApp().run()

Widgets

Kivy uses widgets as the basic building block for GUIs (Graphical User Interfaces). Widgets are objects which can be layed out on your screen and which perform specific tasks. Some examples are input fields, buttons and drop down menus. In this section, you will find an example of widgets we will use in the class as well as specific parameters which can control individual widgets. If you feel like digging deeper into your options, the kivy documentation can be found here.

Label

The label widget is used to create text on your screen.

  • text: "Hello World"

    • Displays "Hello World" on the interface

  • color: 1, 0, 0, 1

    • Color takes 4 numbers from 0 - 1. These correspond to RGB and Alpha

  • font_size: 32

    • Sets the font to 32 pt

  • markup: True

    • Allows you to add markups such as bold, italics, font in your text

    • [b] Bold [/b], [i] italics[/i], [font=times] Change the font to times [/font]

    • [s] strikethrough [/s], [u] underline [/u], [color=#hexcolor] change color [/color]

  • size_hint: 0.5, 0.5

    • changes the size of the text box in relation to horizontal width of the window and vertical height of the window.

  • size: 200, 200

    • Changes the size of the text BOX, not the text.


Button


TextInput

Last updated