Add Label to a Kivy Window Python (original) (raw)

Last Updated : 27 Jan, 2026

A Label is a widget used in Kivy to display text on the screen. It can render both ASCII and Unicode strings, allowing you to show titles, messages, and instructions in your GUI.

**Example: This example creates a minimal Kivy app that displays a single label.

Python `

import kivy from kivy.app import App from kivy.uix.label import Label

kivy.require('1.11.1')

class A(App): def build(self): return Label(text='Hello Kivy')

A().run()

`

**Output

BasicLabelOutput

Kivy window displaying a single label with the text “Hello Kivy”

**Explanation:

Styled Label

A styled label allows you to modify the appearance of text by changing its font size, color and other properties. It helps make the text more readable and visually appealing.

**Example: This example shows how to change font size and text color.

Python `

import kivy from kivy.app import App from kivy.uix.label import Label

kivy.require('1.11.1')

class B(App): def build(self): return Label(text='Styled Label', font_size='24sp', color=(0.2, 0.6, 0.9, 1))

B().run()

`

**Output

StyledLabelOutput

Demonstrates the label with increased font size and a custom bluish color

**Explanation:

Multiline and Alignment

When you need to display multiple lines of text, you can use newline characters (\n) in combination with alignment options. Kivy’s label supports both horizontal and vertical alignment for well-structured text.

**Example: This example demonstrates multiline text and horizontal alignment.

Python `

import kivy from kivy.app import App from kivy.uix.label import Label

kivy.require('1.11.1')

class C(App): def build(self): return Label( text='Line one\nLine two\nLine three', font_size='18sp', halign='center', valign='middle', text_size=(300, None) )

C().run()

`

**Output

MultilineLabelOutput

Displays a multiline label with text centered horizontally and vertically within a fixed width.

**Explanation:

Markup Text

Markup allows you to style parts of the text within a label using BBCode-like tags. You can make text bold, colored, italic, underlined and more, without using multiple label widgets.

**Example: This example enables Kivy markup to style parts of the label text.

Python `

import kivy from kivy.app import App from kivy.uix.label import Label

kivy.require('1.11.1')

class D(App): def build(self): return Label( text='[b]Bold[/b] and [color=ff3333]Red[/color] text', markup=True, font_size='20sp' )

D().run()

`

**Output

MarkupLabelOutput

Shows styled text using markup - bold text and colored text rendered in the label

**Explanation:

MDLabel (KivyMD)

MDLabel is part of the KivyMD library, which follows Google’s Material Design guidelines. It allows you to create labels with predefined styles, themes, and better visual consistency.

Before running the example, install the latest version of KivyMD library using following command:

pip install https://github.com/kivymd/KivyMD/archive/master.zip

**Example: This code creates a window with a Material-styled label positioned at the center.

Python `

from kivymd.app import MDApp from kivymd.uix.label import MDLabel from kivymd.uix.screen import Screen

class MDEx(MDApp): def build(self): self.theme_cls.theme_style = "Light"
self.theme_cls.primary_palette = "Blue"

    screen = Screen()

    label = MDLabel(
        text="Welcome!",
        pos_hint={"center_x": 0.5, "center_y": 0.5},
        theme_text_color="Custom",
        text_color=(0.9, 0.2, 0.5, 1),
        halign="center"
    )

    screen.add_widget(label)
    return screen

MDEx().run()

`

**Output

MDLabel

Shows a Material Design-styled label in a KivyMD window, centered on the screen with custom color applied

**Explanation:

**Note: In the latest KivyMD versions, do not use font_style directly unless you check available font styles, as older styles like H5 or Body1 may cause KeyError.