question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add High DPI support

See original GitHub issue

Try 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

image

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)

image

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)
python_pQkYLY149M

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
daniilScommented, Nov 25, 2021

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.

0reactions
israel-dryercommented, Nov 30, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found