Available Modes
CustomTkinter supports three appearance modes:- Light: Light color scheme for all widgets
- Dark: Dark color scheme for all widgets
- System: Automatically follows the system’s appearance settings (macOS/Windows)
The system mode uses the
darkdetect library to detect the operating system’s theme and updates automatically when it changes.Setting Appearance Mode
Use theset_appearance_mode() function to change the appearance mode:
Getting Current Mode
Retrieve the current appearance mode withget_appearance_mode():
The
get_appearance_mode() function always returns the actual current mode (“Light” or “Dark”), even if you set it to “system”.Complete Example
Here’s a complete example with a toggle button:How It Works
Internal Implementation Details
Internal Implementation Details
CustomTkinter uses an
AppearanceModeTracker class that:- Tracks Mode State: Maintains the current appearance mode (0 for Light, 1 for Dark)
- System Detection: Uses the
darkdetectlibrary to detect system theme changes - Callback System: Registers callbacks for all widgets that update when the mode changes
- Auto-Update Loop: Runs every 30ms to check for system theme changes when in “system” mode
set_appearance_mode():- The mode is stored internally
- All registered widget callbacks are triggered
- Widgets redraw themselves with the new color scheme
System Mode Behavior
- macOS
- Windows
- Linux
Automatically detects light/dark mode from System Preferences. Updates in real-time when you toggle “Dark Mode” in settings.
Best Practices
- Set mode early: Call
set_appearance_mode()before creating your main window for consistent initial rendering - Provide user control: Give users an option to override system settings if they prefer a specific mode
- Test both modes: Always test your UI in both light and dark modes to ensure good contrast and readability
- Consider custom colors: Some custom colors may not look good in both modes - use theme-aware colors when possible
Related Functions
set_appearance_mode(mode_string)- Set the appearance modeget_appearance_mode()- Get the current active modeset_default_color_theme()- Set color theme (see Themes)