style method.
The style Method
The appearance of a widget can be changed by calling itsstyle method:
Built-in Style Functions
Most widgets provide convenience styling functions in their respective modules:Container Styles
Button Styles
Text Styles
Custom Styles
Thestyle method takes a closure that receives the current active Theme and returns the widget style:
Widget Status
Widgets that can be in multiple states provide aStatus parameter:
Working with Palettes
You can extract colors from aTheme using the palette or extended_palette methods:
Basic Palette
Extended Palette
Complete Styling Example
Here’s a comprehensive example showing various widget styles:Styling with Borders and Shadows
Best Practices
Use built-in style functions first
Use built-in style functions first
Before writing custom styles, check if the widget module provides a suitable built-in style function like
button::primary or container::rounded_box.Extract palette colors
Extract palette colors
Always use colors from
theme.palette() or theme.extended_palette() to ensure your styles adapt to theme changes.Handle all status variants
Handle all status variants
When styling interactive widgets, make sure to handle all status variants (Active, Hovered, Pressed, Disabled) for a polished user experience.
Reuse style functions
Reuse style functions
Create reusable style functions for common patterns in your application:
Next Steps
Theming
Learn about theme system and built-in themes
Layout
Master layout composition
