Theming¶
Material App¶
The main class of your application, which in Kivy inherits from the App class,
in KivyMD must inherit from the MDApp class. The MDApp class has
properties that allow you to control application properties
such as color/style/font of interface elements and much more.
Control material properties¶
The main application class inherited from the MDApp class has the theme_cls
attribute, with which you control the material properties of your application.
API - kivymd.theming¶
-
class
kivymd.theming.ThemeManager(**kwargs)¶ Bases:
kivy.event.EventDispatcher-
primary_palette¶ The name of the color scheme that the application will use. All major material components will have the color of the specified color theme.
Available options are: ‘Red’, ‘Pink’, ‘Purple’, ‘DeepPurple’, ‘Indigo’, ‘Blue’, ‘LightBlue’, ‘Cyan’, ‘Teal’, ‘Green’, ‘LightGreen’, ‘Lime’, ‘Yellow’, ‘Amber’, ‘Orange’, ‘DeepOrange’, ‘Brown’, ‘Gray’, ‘BlueGray’.
To change the color scheme of an application:
from kivy.uix.screenmanager import Screen from kivymd.app import MDApp from kivymd.uix.button import MDRectangleFlatButton class MainApp(MDApp): def build(self): self.theme_cls.primary_palette = "Green" # "Purple", "Red" screen = Screen() screen.add_widget( MDRectangleFlatButton( text="Hello, World", pos_hint={"center_x": 0.5, "center_y": 0.5}, ) ) return screen MainApp().run()
primary_paletteis anOptionPropertyand defaults to ‘Blue’.
-
primary_hue¶ The color hue of the application.
Available options are: ‘50’, ‘100’, ‘200’, ‘300’, ‘400’, ‘500’, ‘600’, ‘700’, ‘800’, ‘900’, ‘A100’, ‘A200’, ‘A400’, ‘A700’.
To change the hue color scheme of an application:
from kivy.uix.screenmanager import Screen from kivymd.app import MDApp from kivymd.uix.button import MDRectangleFlatButton class MainApp(MDApp): def build(self): self.theme_cls.primary_palette = "Green" # "Purple", "Red" self.theme_cls.primary_hue = "200" # "500" screen = Screen() screen.add_widget( MDRectangleFlatButton( text="Hello, World", pos_hint={"center_x": 0.5, "center_y": 0.5}, ) ) return screen MainApp().run()
With a value of
self.theme_cls.primary_hue = "500":
With a value of
self.theme_cls.primary_hue = "200":
primary_hueis anOptionPropertyand defaults to ‘500’.
-
primary_light_hue¶ Hue value for
primary_light.primary_light_hueis anOptionPropertyand defaults to ‘200’.
-
primary_dark_hue¶ Hue value for
primary_dark.primary_light_hueis anOptionPropertyand defaults to ‘700’.
-
primary_color¶ The color of the current application theme in
rgbaformat.primary_coloris anAliasPropertythat returns the value of the current application theme, property is readonly.
-
primary_light¶ Colors of the current application color theme in
rgbaformat (in lighter color).from kivy.lang import Builder from kivymd.app import MDApp KV = ''' Screen: MDRaisedButton: text: "primary_light" pos_hint: {"center_x": 0.5, "center_y": 0.7} md_bg_color: app.theme_cls.primary_light MDRaisedButton: text: "primary_color" pos_hint: {"center_x": 0.5, "center_y": 0.5} MDRaisedButton: text: "primary_dark" pos_hint: {"center_x": 0.5, "center_y": 0.3} md_bg_color: app.theme_cls.primary_dark ''' class MainApp(MDApp): def build(self): self.theme_cls.primary_palette = "Green" return Builder.load_string(KV) MainApp().run()
primary_lightis anAliasPropertythat returns the value of the current application theme (in lighter color), property is readonly.
-
primary_dark¶ Colors of the current application color theme in
rgbaformat (in darker color).primary_darkis anAliasPropertythat returns the value of the current application theme (in darker color), property is readonly.
-
accent_palette¶ The application color palette used for items such as the tab indicator in the
MDTabsBarclass and so on…The image below shows the color schemes with the values
self.theme_cls.accent_palette = 'Blue',Red'andYellow':
primary_hueis anOptionPropertyand defaults to ‘Amber’.
-
accent_hue¶ Similar to
primary_hue, but returns a value foraccent_palette.accent_hueis anOptionPropertyand defaults to ‘500’.
-
accent_light_hue¶ Hue value for
accent_light.accent_light_hueis anOptionPropertyand defaults to ‘200’.
-
accent_dark_hue¶ Hue value for
accent_dark.accent_dark_hueis anOptionPropertyand defaults to ‘700’.
-
accent_color¶ Similar to
primary_color, but returns a value foraccent_color.accent_coloris anAliasPropertythat returns the value inrgbaformat foraccent_color, property is readonly.
-
accent_light¶ Similar to
primary_light, but returns a value foraccent_light.accent_lightis anAliasPropertythat returns the value inrgbaformat foraccent_light, property is readonly.
-
accent_dark¶ Similar to
primary_dark, but returns a value foraccent_dark.accent_darkis anAliasPropertythat returns the value inrgbaformat foraccent_dark, property is readonly.
-
theme_style¶ App theme style.
from kivy.uix.screenmanager import Screen from kivymd.app import MDApp from kivymd.uix.button import MDRectangleFlatButton class MainApp(MDApp): def build(self): self.theme_cls.theme_style = "Dark" # "Light" screen = Screen() screen.add_widget( MDRectangleFlatButton( text="Hello, World", pos_hint={"center_x": 0.5, "center_y": 0.5}, ) ) return screen MainApp().run()
theme_styleis anOptionPropertyand defaults to ‘Light’.
-
bg_darkest¶ Similar to
bg_dark, but the color values are a tone lower (darker) thanbg_dark.KV = ''' <Box@BoxLayout>: bg: 0, 0, 0, 0 canvas: Color: rgba: root.bg Rectangle: pos: self.pos size: self.size BoxLayout: Box: bg: app.theme_cls.bg_light Box: bg: app.theme_cls.bg_normal Box: bg: app.theme_cls.bg_dark Box: bg: app.theme_cls.bg_darkest ''' from kivy.lang import Builder from kivymd.app import MDApp class MainApp(MDApp): def build(self): self.theme_cls.theme_style = "Dark" # "Light" return Builder.load_string(KV) MainApp().run()
bg_darkestis anAliasPropertythat returns the value inrgbaformat forbg_darkest, property is readonly.
-
opposite_bg_darkest¶ The opposite value of color in the
bg_darkest.opposite_bg_darkestis anAliasPropertythat returns the value inrgbaformat foropposite_bg_darkest, property is readonly.
-
bg_dark¶ Similar to
bg_normal, but the color values are one tone lower (darker) thanbg_normal.bg_darkis anAliasPropertythat returns the value inrgbaformat forbg_dark, property is readonly.
-
opposite_bg_dark¶ The opposite value of color in the
bg_dark.opposite_bg_darkis anAliasPropertythat returns the value inrgbaformat foropposite_bg_dark, property is readonly.
-
bg_normal¶ Similar to
bg_light, but the color values are one tone lower (darker) thanbg_light.bg_normalis anAliasPropertythat returns the value inrgbaformat forbg_normal, property is readonly.
-
opposite_bg_normal¶ The opposite value of color in the
bg_normal.opposite_bg_normalis anAliasPropertythat returns the value inrgbaformat foropposite_bg_normal, property is readonly.
-
bg_light¶ ” Depending on the style of the theme (‘Dark’ or ‘Light’) that the application uses,
bg_lightcontains the color value inrgbaformat for the widgets background.bg_lightis anAliasPropertythat returns the value inrgbaformat forbg_light, property is readonly.
-
opposite_bg_light¶ The opposite value of color in the
bg_light.opposite_bg_lightis anAliasPropertythat returns the value inrgbaformat foropposite_bg_light, property is readonly.
-
divider_color¶ Color for dividing lines such as
MDSeparator.divider_coloris anAliasPropertythat returns the value inrgbaformat fordivider_color, property is readonly.
-
opposite_divider_color¶ The opposite value of color in the
divider_color.opposite_divider_coloris anAliasPropertythat returns the value inrgbaformat foropposite_divider_color, property is readonly.
-
text_color¶ Color of the text used in the
MDLabel.text_coloris anAliasPropertythat returns the value inrgbaformat fortext_color, property is readonly.
-
opposite_text_color¶ The opposite value of color in the
text_color.opposite_text_coloris anAliasPropertythat returns the value inrgbaformat foropposite_text_color, property is readonly.
-
secondary_text_color¶ The color for the secondary text that is used in classes from the module
TwoLineListItem.secondary_text_coloris anAliasPropertythat returns the value inrgbaformat forsecondary_text_color, property is readonly.
-
opposite_secondary_text_color¶ The opposite value of color in the
secondary_text_color.opposite_secondary_text_coloris anAliasPropertythat returns the value inrgbaformat foropposite_secondary_text_color, property is readonly.
-
icon_color¶ Color of the icon used in the
MDIconButton.icon_coloris anAliasPropertythat returns the value inrgbaformat foricon_color, property is readonly.
-
opposite_icon_color¶ The opposite value of color in the
icon_color.opposite_icon_coloris anAliasPropertythat returns the value inrgbaformat foropposite_icon_color, property is readonly.
-
disabled_hint_text_color¶ Color of the disabled text used in the
MDTextField.disabled_hint_text_coloris anAliasPropertythat returns the value inrgbaformat fordisabled_hint_text_color, property is readonly.
-
opposite_disabled_hint_text_color¶ The opposite value of color in the
disabled_hint_text_color.opposite_disabled_hint_text_coloris anAliasPropertythat returns the value inrgbaformat foropposite_disabled_hint_text_color, property is readonly.
-
error_color¶ Color of the error text used in the
MDTextField.error_coloris anAliasPropertythat returns the value inrgbaformat forerror_color, property is readonly.
-
ripple_color¶ Color of ripple effects.
ripple_coloris anAliasPropertythat returns the value inrgbaformat forripple_color, property is readonly.
-
device_orientation¶ Device orientation.
device_orientationis anStringProperty.
-
standard_increment¶ Value of standard increment.
standard_incrementis anAliasPropertythat returns the value inrgbaformat forstandard_increment, property is readonly.
-
horizontal_margins¶ Value of horizontal margins.
horizontal_marginsis anAliasPropertythat returns the value inrgbaformat forhorizontal_margins, property is readonly.
-
set_clearcolor¶
-
font_styles¶ Data of default font styles.
Add custom font:
KV = ''' Screen: MDLabel: text: "JetBrainsMono" halign: "center" font_style: "JetBrainsMono" ''' from kivy.core.text import LabelBase from kivy.lang import Builder from kivymd.app import MDApp from kivymd.font_definitions import theme_font_styles class MainApp(MDApp): def build(self): LabelBase.register( name="JetBrainsMono", fn_regular="JetBrainsMono-Regular.ttf") theme_font_styles.append('JetBrainsMono') self.theme_cls.font_styles["JetBrainsMono"] = [ "JetBrainsMono", 16, False, 0.15, ] return Builder.load_string(KV) MainApp().run()
font_stylesis anDictProperty.
-
on_theme_style(self, instance, value)¶
-
set_clearcolor_by_theme_style(self, theme_style)¶
-
-
class
kivymd.theming.ThemableBehavior(**kwargs)¶ Bases:
kivy.event.EventDispatcher-
theme_cls¶ Instance of
ThemeManagerclass.theme_clsis anObjectProperty.
-
device_ios¶ Trueif device isiOS.device_iosis anBooleanProperty.
-
opposite_colors¶
-