Scaling Types
CustomTkinter supports two independent scaling factors:- Widget Scaling: Scales the size of all widgets (buttons, labels, frames, etc.)
- Window Scaling: Scales window dimensions and geometry
Widget Scaling
Control the size of all widgets withset_widget_scaling():
Widget scaling affects all widget dimensions including padding, border widths, corner radius, and font sizes.
Window Scaling
Control window dimensions withset_window_scaling():
Window scaling affects window geometry (width/height) but does not affect widget sizes. Use both together for proportional scaling.
Complete Example
Automatic DPI Awareness
CustomTkinter automatically detects and handles DPI scaling on Windows and macOS:- Windows
- macOS
- Linux
CustomTkinter calls
SetProcessDpiAwareness(2) to enable per-monitor DPI awareness. The application detects DPI changes when moved between monitors with different scaling factors.DPI is checked every 100ms and widgets are automatically redrawn when the scaling changes.Disabling Automatic DPI Awareness
If you want to handle DPI scaling yourself, disable automatic detection:You must call
deactivate_automatic_dpi_awareness() before creating any windows. This sets a flag that prevents DPI detection from being activated.Scaling Limits
Both widget and window scaling have minimum values:The minimum scaling value of 0.4 prevents widgets from becoming too small to be usable.
How Scaling Works
Internal Implementation
Internal Implementation
The
ScalingTracker class manages all scaling operations:- Widget Registration: Each widget registers a callback when created
- DPI Detection: On Windows, uses
GetDpiForMonitor()to detect monitor DPI - Scaling Calculation: Final scaling =
detected_dpi_scaling × user_scaling - Update Loop: Checks for DPI changes every 100ms on active windows
- Callback Execution: When scaling changes, all registered callbacks are triggered
- Widget Redraw: Each widget recalculates its dimensions and redraws
widget_scaling: User-set widget scaling factor (default: 1.0)window_scaling: User-set window scaling factor (default: 1.0)window_dpi_scaling_dict: Detected DPI scaling per window
- Monitor DPI: 144 (150% scaling in Windows)
- Detected DPI factor: 144 / 96 = 1.5
- User widget scaling: 1.2
- Final widget scaling: 1.5 × 1.2 = 1.8
Best Practices
- Set scaling early: Call scaling functions before creating windows for consistent initial rendering
- Test on different DPIs: Test your application on monitors with different scaling factors (100%, 125%, 150%, 200%)
- Provide user controls: Allow users to adjust scaling if the automatic detection doesn’t match their preferences
- Use relative layouts: Use
pack(),grid(), andplace()with relative positioning for better scaling behavior - Avoid fixed sizes: Prefer
fill="both"andexpand=Trueover fixed pixel dimensions
Common Use Cases
Accessibility - Larger UI
Compact UI
User Preference
Related Functions
set_widget_scaling(scaling_value)- Set widget scaling factorset_window_scaling(scaling_value)- Set window scaling factordeactivate_automatic_dpi_awareness()- Disable automatic DPI detectionCTkFont- Fonts scale automatically with widget scaling (see Fonts and Images)CTkImage- Images scale automatically (see Fonts and Images)