Set of widgets for Kivy inspired by Google's Material Design
—
Text display and input components that follow Material Design specifications for typography, text fields, and selection controls. These components provide consistent text styling, input validation, and interaction patterns across the application.
Components for displaying text with Material Design typography and theming.
class MDLabel:
"""
Material Design label for displaying text.
Text display widget that follows Material Design typography guidelines
with automatic theming and font styling.
"""
text: str # Label text content
theme_text_color: str # Text color theme: "Primary", "Secondary", "Hint", "Error", "Custom"
text_color: list # Custom text color as RGBA
font_style: str # Font style: "H1", "H2", "H3", "H4", "H5", "H6", "Subtitle1", "Subtitle2", "Body1", "Body2", "Button", "Caption", "Overline"
halign: str # Horizontal alignment: "left", "center", "right", "justify"
valign: str # Vertical alignment: "top", "middle", "bottom"
markup: bool # Enable markup text formatting
class MDIcon:
"""
Material Design icon display widget.
Displays Material Design icons with consistent sizing and theming.
"""
icon: str # Icon name from md_icons dictionary
theme_icon_color: str # Icon color theme: "Primary", "Secondary", "Hint", "Error", "Custom"
icon_color: list # Custom icon color as RGBA
user_font_size: str # Icon size (e.g., "24sp", "32sp")
def set_icon(self, icon_name: str):
"""
Set the displayed icon.
Args:
icon_name (str): Icon name from md_icons dictionary
"""Text input components with Material Design styling, validation, and helper text.
class MDTextField:
"""
Material Design text input field.
Text input widget with Material Design styling including floating labels,
helper text, error states, and validation.
"""
text: str # Current text content
hint_text: str # Placeholder text when field is empty
helper_text: str # Helper text displayed below field
helper_text_mode: str # Helper text mode: "none", "on_focus", "persistent", "on_error"
# Validation and error states
error: bool # Error state flag
required: bool # Required field flag
text_validate_unfocus: bool # Validate on unfocus
# Text formatting
multiline: bool # Allow multiple lines
password: bool # Password field (hidden text)
input_filter: str # Input filter: "int", "float", None
# Visual styling
mode: str # Field mode: "line", "rectangle", "fill"
line_color_normal: list # Normal line color
line_color_focus: list # Focus line color
fill_color_normal: list # Normal fill color
fill_color_focus: list # Focus fill color
# Sizing
max_text_length: int # Maximum text length
font_size: str # Font size (e.g., "14sp")
def on_text_validate(self):
"""Called when text is validated (Enter pressed)."""
def on_focus(self, instance, focus: bool):
"""Called when focus changes."""
class MDTextFieldRect:
"""
Rectangular Material Design text field.
Text field with rectangular border styling instead of underline.
"""
text: str # Current text content
hint_text: str # Placeholder text
multiline: bool # Allow multiple lines
readonly: bool # Read-only mode
# Styling
normal_color: list # Normal border color
focus_color: list # Focus border color
line_width: float # Border line widthInput controls for user selection including checkboxes, switches, and sliders.
class MDCheckbox:
"""
Material Design checkbox.
Binary selection control with Material Design styling and animations.
"""
active: bool # Checkbox state (checked/unchecked)
disabled: bool # Disabled state
checkbox_icon_normal: str # Unchecked icon
checkbox_icon_down: str # Checked icon
# Colors
selected_color: list # Selected state color
unselected_color: list # Unselected state color
disabled_color: list # Disabled state color
def on_active(self, instance, active: bool):
"""Called when checkbox state changes."""
class MDSwitch:
"""
Material Design switch.
Toggle switch for binary on/off states with smooth animations.
"""
active: bool # Switch state (on/off)
disabled: bool # Disabled state
# Visual properties
thumb_color_active: list # Active thumb color
thumb_color_inactive: list # Inactive thumb color
track_color_active: list # Active track color
track_color_inactive: list # Inactive track color
def on_active(self, instance, active: bool):
"""Called when switch state changes."""
class Thumb:
"""
Thumb component for switches.
Visual thumb element that slides along the switch track.
"""
class MDSlider:
"""
Material Design slider.
Continuous selection control for choosing values from a range.
"""
value: float # Current slider value
min: float # Minimum value
max: float # Maximum value
step: float # Value increment step
# Visual styling
color: list # Slider color
track_color_active: list # Active track color
track_color_inactive: list # Inactive track color
thumb_color_active: list # Active thumb color
thumb_color_inactive: list # Inactive thumb color
# Display options
show_off: bool # Show value when not active
hint: bool # Show hint bubble with value
def on_value(self, instance, value: float):
"""Called when slider value changes."""from kivymd.uix.label import MDLabel, MDIcon
from kivymd.uix.boxlayout import MDBoxLayout
# Create layout
layout = MDBoxLayout(
orientation="vertical",
spacing="16dp",
adaptive_height=True,
padding="16dp"
)
# Title label
title = MDLabel(
text="Material Design App",
font_style="H4",
theme_text_color="Primary",
halign="center"
)
# Body text
body = MDLabel(
text="This is body text using Material Design typography.",
font_style="Body1",
theme_text_color="Primary",
halign="center"
)
# Icon
icon = MDIcon(
icon="heart",
theme_icon_color="Error",
user_font_size="48sp",
pos_hint={"center_x": 0.5}
)
layout.add_widget(title)
layout.add_widget(body)
layout.add_widget(icon)from kivymd.uix.textfield import MDTextField
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.button import MDRaisedButton
# Create form layout
form = MDBoxLayout(
orientation="vertical",
spacing="16dp",
adaptive_height=True,
padding="16dp"
)
# Name field
name_field = MDTextField(
hint_text="Enter your name",
helper_text="Required field",
helper_text_mode="persistent",
required=True,
mode="rectangle"
)
# Email field
email_field = MDTextField(
hint_text="Enter your email",
helper_text="We'll never share your email",
helper_text_mode="on_focus",
input_filter=None, # Could add email validation
mode="rectangle"
)
# Password field
password_field = MDTextField(
hint_text="Enter password",
helper_text="Minimum 8 characters",
password=True,
mode="rectangle"
)
# Submit button
submit_button = MDRaisedButton(
text="Submit",
pos_hint={"center_x": 0.5}
)
form.add_widget(name_field)
form.add_widget(email_field)
form.add_widget(password_field)
form.add_widget(submit_button)from kivymd.uix.selectioncontrol import MDCheckbox, MDSwitch
from kivymd.uix.slider import MDSlider
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.label import MDLabel
# Create controls layout
controls = MDBoxLayout(
orientation="vertical",
spacing="24dp",
adaptive_height=True,
padding="16dp"
)
# Checkbox
checkbox = MDCheckbox(
active=False,
size_hint=(None, None),
size=("48dp", "48dp"),
pos_hint={"center_x": 0.5}
)
checkbox_label = MDLabel(
text="Accept terms and conditions",
theme_text_color="Primary"
)
# Switch
switch = MDSwitch(
active=True,
pos_hint={"center_x": 0.5}
)
switch_label = MDLabel(
text="Enable notifications",
theme_text_color="Primary"
)
# Slider
slider = MDSlider(
min=0,
max=100,
value=50,
step=1,
hint=True,
size_hint_x=0.8,
pos_hint={"center_x": 0.5}
)
slider_label = MDLabel(
text="Volume",
theme_text_color="Primary"
)
# Add to layout
controls.add_widget(checkbox_label)
controls.add_widget(checkbox)
controls.add_widget(switch_label)
controls.add_widget(switch)
controls.add_widget(slider_label)
controls.add_widget(slider)from kivymd.uix.textfield import MDTextField
class ValidatedTextField(MDTextField):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.bind(text=self.on_text_change)
def on_text_change(self, instance, text):
"""Validate text input."""
if self.required and not text.strip():
self.error = True
self.helper_text = "This field is required"
elif len(text) < 3:
self.error = True
self.helper_text = "Minimum 3 characters required"
else:
self.error = False
self.helper_text = "Looks good!"
# Usage
validated_field = ValidatedTextField(
hint_text="Username",
required=True,
helper_text_mode="persistent",
mode="rectangle"
)Install with Tessl CLI
npx tessl i tessl/pypi-kivymd