Add High DPI support
See original GitHub issueTry to find a way to support High DPI awareness out-of-the-box. The easiest way might be some kind of parameter added to the Tk
widget that enables certain OS specific settings and possibly calculates the appropriate scaling by default while allowing for overides.
Without High DPI Awareness
The application is running on Windows 11 without high DPI awareness
- images and fonts are noticeably pixelated on a 4k screen, not quite so noticeable on 2k
- relative scaling of widgets appears ok
High DPI Awareness Enabled (No Tk Scaling)
The exhibit below illustrates the application on Windows 11 with DPI awareness turned on
- image-based layouts are too small as they are not scaled appropriately
- fonts are not consistently scaled, too big in some cases, too small in others
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(1)
High DPI Awareness Enabled (Tk Scaling = 1.5)
The exhibit below illustrates the application on Windows 11 with DPI awareness turned on and additional scaling settings configured using tkinter.
- the widgets and fonts all appear crisp and scaled correctly
- the application window size is noticeably smaller
- the titlebar looks a bit too big relative to the window size
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(1)
# after creating root
root.tk.call('tk', 'scaling', 1.5)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
High DPI support - Windows Forms .NET Framework
Configuring your Windows Forms app for high DPI support · Declare compatibility with Windows 10. To do this, add the following to your...
Read more >High DPI Support in Windows Forms Controls - Syncfusion
Enable high DPI support · Right click the sample project. · Click Add , select New Item or press the CTRL+SHIFT+A shortcut. ·...
Read more >Adding Support for High DPI Settings | Spread Windows ...
Use the following steps to enable DPI support. Install the .NET 4.7 Framework. Create a new windows forms application. Add an App.config with...
Read more >Graphics Performance and High DPI | WinForms Controls
This article explains how to develop DevExpress-based applications that can be viewed on high DPI devices without loss of quality.
Read more >WinForms Scaling at Large DPI Settings–Is It Even Possible?
The standard settings are 100% (96 DPI), 125% (120 DPI), and 150% (144 DPI). Windows 8 removed the numerical values and added some...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Leaving a comment here to remind myself to respond properly in a few days - I’ve done a lot of playing around with tk scaling on Windows so will need to remember what exactly I’d found.
To scale the titlebar appropriately, I think one of the options of SetThreadDipAwareness (rather than Process) did the trick. However, I found that almost all of the options had some issues with them when a window is created on one monitor, and then dragged to another monitor with a different DPI (the joys of using a laptop + an external monitor). I ended up settling for DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED as a compromise myself.
while documenting the library, I realized I needed to flatten the modules, and that let me to refactoring several items. The only thing that really changes from an api perspective was the utility module, which is now in the root.
So, this method is now in
ttkbootrap.utility.enable_high_dpi_awareness