Label
The Class To use a custom color for You can use labels to display material design icons using the
The Warning For the MDLabel
widget is for rendering text.
MDLabel
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"
MDTopAppBar:
title: "MDLabel"
MDLabel:
text: "MDLabel"
'''
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
Test().run()
MDLabel:
text: "MDLabel"
halign: "center"
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"
MDTopAppBar:
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()
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
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"
MDTopAppBar:
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()
MDIcon
MDIcon
class.MDIcon
class is inherited from
MDLabel
and has the same parameters.MDIcon
class, you cannot use text
and font_style
options!MDIcon:
icon: "gmail"
pos_hint: {"center_x": .5, "center_y": .5}
MDIcon with badge icon
MDIcon:
icon: "gmail"
badge_icon: "numeric-10"
pos_hint: {"center_x": .5, "center_y": .5}
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 anStringProperty
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 anOptionProperty
and defaults to None.
- text_color
Label text color in (r, g, b, a) format.
text_color
is anColorProperty
and defaults to None.
- parent_background
- can_capitalize
- 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 anStringProperty
and defaults to ‘android’.
- badge_icon
Label badge icon name.
New in version 1.0.0.
badge_icon
is anStringProperty
and defaults to ‘’.
- badge_icon_color
Badge icon color in (r, g, b, a) format.
New in version 1.0.0.
badge_icon_color
is anColorProperty
and defaults to None.
- badge_bg_color
Badge icon background color in (r, g, b, a) format.
New in version 1.0.0.
badge_bg_color
is anColorProperty
and defaults to None.
- badge_font_size
Badge font size.
New in version 1.0.0.
badge_font_size
is anNumericProperty
and defaults to 0.
- source
Path to icon.
source
is anStringProperty
and defaults to None.