Set of widgets for Kivy inspired by Google's Material Design
—
Core application classes and theming system for Material Design applications. This includes the main app class that integrates Material Design theming, the theme management system, and all Material Design resource definitions including colors, icons, and typography.
The main application class that provides Material Design theming integration and serves as the entry point for KivyMD applications.
class MDApp:
"""
Main application class with integrated Material Design theming.
This class extends Kivy's App class with Material Design theming capabilities.
It automatically sets up the theme manager and provides access to Material Design
resources throughout the application.
"""
theme_cls: ThemeManager # Theme manager instance
icon: str # App icon path (default: "kivymd/images/logo/kivymd-icon-512.png")
def build(self):
"""
Build and return the root widget.
Returns:
Widget: Root widget of the application
"""
def on_start(self):
"""Called when the application starts."""
def on_stop(self):
"""Called when the application stops."""
def load_all_kv_files(self, path_to_directory: str):
"""
Load all KV files from specified directory recursively.
Searches through all subdirectories and loads any .kv files found.
Useful for automatically loading UI definitions.
Args:
path_to_directory (str): Path to directory containing KV files
"""
def fps_monitor_start(self):
"""
Start FPS monitoring display.
Shows real-time FPS counter on screen for performance monitoring.
Available through FpsMonitoring mixin.
"""Central theming system that manages Material Design colors, typography, and visual specifications across the entire application.
class ThemeManager:
"""
Central theme management system for Material Design theming.
Manages all aspects of Material Design theming including color palettes,
typography, spacing, and visual specifications.
"""
# Color theming
primary_palette: str # Primary color palette name (e.g., "Blue", "Red")
accent_palette: str # Accent color palette name
theme_style: str # Theme style: "Light" or "Dark"
material_style: str # Material Design version: "M2" or "M3"
# Color hue properties
primary_hue: str # Primary palette hue (e.g., "500")
primary_light_hue: str # Light primary hue
primary_dark_hue: str # Dark primary hue
accent_hue: str # Accent palette hue
accent_light_hue: str # Light accent hue
accent_dark_hue: str # Dark accent hue
# Color properties
primary_color: list # Primary color as RGBA
primary_light: list # Light primary color as RGBA
primary_dark: list # Dark primary color as RGBA
accent_color: list # Accent color as RGBA
bg_darkest: list # Darkest background color
bg_dark: list # Dark background color
bg_normal: list # Normal background color
bg_light: list # Light background color
# Text colors
text_color: list # Primary text color
secondary_text_color: list # Secondary text color
disabled_hint_text_color: list # Disabled text color
divider_color: list # Divider color
error_color: list # Error color
# Animation properties
theme_style_switch_animation: bool # Enable theme switching animation
theme_style_switch_animation_duration: float # Animation duration
# Font styles
font_styles: dict # Complete font style definitions
# Material Design specifications
device_orientation: str # "portrait" or "landscape"
standard_increment: int # Standard increment in dp
horizontal_margins: int # Horizontal margins in dp
def set_colors(self, primary: str, accent: str, theme_style: str = "Light",
light_primary: str = None, light_accent: str = None,
dark_primary: str = None, dark_accent: str = None,
primary_hue: str = None):
"""
Set comprehensive theme colors.
Args:
primary (str): Primary palette name
accent (str): Accent palette name
theme_style (str): "Light" or "Dark"
light_primary (str): Light primary palette name
light_accent (str): Light accent palette name
dark_primary (str): Dark primary palette name
dark_accent (str): Dark accent palette name
primary_hue (str): Primary color hue
"""
class ThemableBehavior:
"""
Mixin behavior that provides theme integration for widgets.
This behavior should be inherited by all widgets that need access
to theme properties and automatic theme updates.
"""
theme_cls: ThemeManager # Reference to theme manager
device_ios: bool # Whether running on iOS device
widget_style: str # Widget style: "android", "ios", or "desktop"
opposite_colors: bool # Use opposite color theming
def theme_cls_bind(self):
"""Bind to theme manager for automatic updates."""
def dec_disabled(self):
"""Cleanup method called when widget is disabled."""Complete Material Design color palette system with all standard colors and utilities for color manipulation.
# Color palette dictionary - contains all Material Design colors
colors: dict # Complete color palette with all hues
# Color palette names
palette: list # Available palette names: ["Red", "Pink", "Purple", ...]
# Color hues
hue: list # Available hues: ["50", "100", "200", ..., "900", "A100", "A200", "A400", "A700"]
# Theme-specific colors
light_colors: dict # Light theme color specifications
text_colors: dict # Text color specifications for different themes
theme_colors: list # Available theme color names
def get_color_from_hex(hex_color: str) -> list:
"""
Convert hex color to RGBA list.
Args:
hex_color (str): Hex color string (e.g., "#FF5722")
Returns:
list: RGBA color as [r, g, b, a] normalized to 0-1
"""Complete Material Design Icons system with over 7000+ icons available as unicode characters.
# Material Design Icons dictionary
md_icons: dict # Icon name to unicode mapping (7000+ icons)
class MDIcon:
"""
Material Design icon display widget.
Displays Material Design icons using the md_icons dictionary.
"""
icon: str # Icon name from md_icons
theme_icon_color: str # Icon color theme
def set_icon(self, icon_name: str):
"""
Set the icon.
Args:
icon_name (str): Icon name from md_icons dictionary
"""Material Design typography system with all standard font styles and text specifications.
# Font definitions
fonts: list # Font definitions for Material Design fonts
theme_font_styles: list # Available font styles
# Font style names and specifications
FONT_STYLES = {
"H1": {"font_size": "96sp", "font_weight": "light"},
"H2": {"font_size": "60sp", "font_weight": "light"},
"H3": {"font_size": "48sp", "font_weight": "normal"},
"H4": {"font_size": "34sp", "font_weight": "normal"},
"H5": {"font_size": "24sp", "font_weight": "normal"},
"H6": {"font_size": "20sp", "font_weight": "medium"},
"Subtitle1": {"font_size": "16sp", "font_weight": "normal"},
"Subtitle2": {"font_size": "14sp", "font_weight": "medium"},
"Body1": {"font_size": "16sp", "font_weight": "normal"},
"Body2": {"font_size": "14sp", "font_weight": "normal"},
"Button": {"font_size": "14sp", "font_weight": "medium"},
"Caption": {"font_size": "12sp", "font_weight": "normal"},
"Overline": {"font_size": "10sp", "font_weight": "normal"}
}Material Design specification constants for consistent spacing, sizing, and layout.
# Device and platform detection
DEVICE_IOS: bool # True if running on iOS
DEVICE_TYPE: str # "desktop", "tablet", or "mobile"
# Layout specifications
MAX_NAV_DRAWER_WIDTH: int # Maximum navigation drawer width in dp
HORIZ_MARGINS: int # Standard horizontal margins in dp
STANDARD_INCREMENT: int # Standard increment for spacing in dp
# Component specifications
PORTRAIT_TOOLBAR_HEIGHT: int # Toolbar height in portrait mode in dp
LANDSCAPE_TOOLBAR_HEIGHT: int # Toolbar height in landscape mode in dp
TOUCH_TARGET_HEIGHT: int # Minimum touch target height in dp
# Elevation specifications
ELEVATION_LEVELS: dict # Standard elevation levels for componentsCore package constants and utility paths for accessing KivyMD resources.
__version__: str # KivyMD version string
# Resource paths
path: str # Path to KivyMD package directory
fonts_path: str # Path to fonts directory
images_path: str # Path to images directory
uix_path: str # Path to UI components directory
glsl_path: str # Path to GLSL shaders directoryInstall with Tessl CLI
npx tessl i tessl/pypi-kivymd