Label¶
The MDLabel
widget is for rendering text.
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 = '''
Screen:
BoxLayout:
orientation: "vertical"
MDToolbar:
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 = '''
Screen:
BoxLayout:
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()
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
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 = '''
Screen:
BoxLayout:
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()
API - kivymd.uix.label
¶
- class kivymd.uix.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
rgba
format.text_color
is anColorProperty
and defaults to None.
- parent_background¶
- can_capitalize¶
- check_font_styles(self, *dt)¶
- update_font_style(self, *args)¶
- on_theme_text_color(self, instance, value)¶
- on_text_color(self, *args)¶
- on_opposite_colors(self, instance, value)¶
- class kivymd.uix.label.MDIcon(**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.
- icon¶
Label icon name.
icon
is anStringProperty
and defaults to ‘android’.
- source¶
Path to icon.
source
is anStringProperty
and defaults to None.