Label

The MDLabel widget is for rendering text.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/label.png

MDLabel

Class MDLabel inherited from the Label class but for MDLabel the text_size parameter is (self.width, None) and default is positioned on the left:

from kivy.lang import Builder

from kivymd.app import MDApp

KV = '''
MDScreen:

    MDBoxLayout:
        orientation: "vertical"

        MDToolbar:
            title: "MDLabel"

        MDLabel:
            text: "MDLabel"
'''


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)


Test().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-label-to-left.png

Note

See halign and valign attributes of the Label class

MDLabel:
    text: "MDLabel"
    halign: "center"
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-label-to-center.png

MDLabel color:

MDLabel provides standard color themes for label color management:

from kivy.lang import Builder

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

KV = '''
MDScreen:

    MDBoxLayout:
        id: box
        orientation: "vertical"

        MDToolbar:
            title: "MDLabel"
'''


class Test(MDApp):
    def build(self):
        screen = Builder.load_string(KV)
        # Names of standard color themes.
        for name_theme in [
            "Primary",
            "Secondary",
            "Hint",
            "Error",
            "ContrastParentBackground",
        ]:
            screen.ids.box.add_widget(
                MDLabel(
                    text=name_theme,
                    halign="center",
                    theme_text_color=name_theme,
                )
            )
        return screen


Test().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-label-theme-text-color.png

To use a custom color for MDLabel, use a theme ‘Custom’. After that, you can specify the desired color in the rgba format in the text_color parameter:

MDLabel:
    text: "Custom color"
    halign: "center"
    theme_text_color: "Custom"
    text_color: 0, 0, 1, 1
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-label-custom-color.png

MDLabel provides standard font styles for labels. To do this, specify the name of the desired style in the font_style parameter:

from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.font_definitions import theme_font_styles


KV = '''
MDScreen:

    MDBoxLayout:
        orientation: "vertical"

        MDToolbar:
            title: "MDLabel"

        ScrollView:

            MDList:
                id: box
'''


class Test(MDApp):
    def build(self):
        screen = Builder.load_string(KV)
        # Names of standard font styles.
        for name_style in theme_font_styles[:-1]:
            screen.ids.box.add_widget(
                MDLabel(
                    text=f"{name_style} style",
                    halign="center",
                    font_style=name_style,
                )
            )
        return screen


Test().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-label-font-style.gif

MDIcon

You can use labels to display material design icons using the MDIcon class.

The MDIcon class is inherited from MDLabel and has the same parameters.

Warning

For the MDIcon class, you cannot use text and font_style options!

MDIcon:
    icon: "gmail"
    pos_hint: {"center_x": .5, "center_y": .5}
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-icon.png

MDIcon with badge icon

MDIcon:
    icon: "gmail"
    badge_icon: "numeric-10"
    pos_hint: {"center_x": .5, "center_y": .5}
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-icon-badge.png

API - kivymd.uix.label.label

class kivymd.uix.label.label.MDLabel(**kwargs)

Label class, see module documentation for more information.

Events
on_ref_press

Fired when the user clicks on a word referenced with a [ref] tag in a text markup.

font_style

Label font style.

Available vanilla font_style are: ‘H1’, ‘H2’, ‘H3’, ‘H4’, ‘H5’, ‘H6’, ‘Subtitle1’, ‘Subtitle2’, ‘Body1’, ‘Body2’, ‘Button’, ‘Caption’, ‘Overline’, ‘Icon’.

font_style is an StringProperty and defaults to ‘Body1’.

text

Text of the label.

theme_text_color

Label color scheme name.

Available options are: ‘Primary’, ‘Secondary’, ‘Hint’, ‘Error’, ‘Custom’, ‘ContrastParentBackground’.

theme_text_color is an OptionProperty and defaults to None.

text_color

Label text color in rgba format.

text_color is an ColorProperty and defaults to None.

parent_background
can_capitalize
check_font_styles(self, interval: Union[int, float] = 0)
update_font_style(self, instance_label, font_style: str)
on_theme_text_color(self, instance_label, theme_text_color: str)
on_text_color(self, instance_label, color: list)
on_opposite_colors(self, *args)
class kivymd.uix.label.label.MDIcon(**kwargs)

Float layout class. See module documentation for more information.

icon

Label icon name.

icon is an StringProperty and defaults to ‘android’.

badge_icon

Label badge icon name.

New in version 1.0.0.

badge_icon is an StringProperty and defaults to ‘’.

badge_icon_color

Badge icon color.

New in version 1.0.0.

badge_icon_color is an ColorProperty and defaults to None.

badge_bg_color

Badge icon background color.

New in version 1.0.0.

badge_bg_color is an ColorProperty and defaults to None.

badge_font_size

Badge icon color.

New in version 1.0.0.

badge_font_size is an NumericProperty and defaults to 0.

source

Path to icon.

source is an StringProperty and defaults to None.