Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

There are a few ways that an application can tell Windows to not upscale/resample it for high-DPI displays (which it does for compatibility at the expense of appearance quality). Microsoft's recommended approach is to use an application manifest, rather than setting DPI awareness programmatically.

But for standalone scripts, setting DPI awareness programmatically seems easier—so much so that I haven't even attempted the application manifest approach :^). The simplest approach might be to invoke SetProcessDPIAware() from User32.dll, which is present in Vista and later. (Newer DPI awareness functions exist in Windows 8.1/10 which allow more specific settings, but I'm not sure Tk would take advantage of them.) That function can be invoked from XS, or from a Perl script by using a module like Win32::API:

# Make sure to do this **before** calling MainWindow->new
if ($^O eq 'MSWin32') {
    require Win32::API;
    # See
    my $SetProcessDPIAware = Win32::API::More->new('User32', 'BOOL SetProcessDPIAware()');
    $SetProcessDPIAware->Call() or warn 'Failed to set process DPI awareness';

This approach works in Perl/Tk, as well as any of the wrappers for modern Tcl/Tk such as Tcl::pTk (disclaimer: I maintain this). There are very likely to be caveats to this approach; for example, although the value of $widget->scaling will be correctly updated, some elements like images will not be resized, and may appear smaller than expected.

Edit 2019-06-24: use Win32::API should instead be require Win32::API . Thanks vkon for catching this.

In reply to Re: Tk Windows 10 Scaling by chrstphrchvz
in thread Tk Windows 10 Scaling by Anonymous Monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2022-11-30 06:15 GMT
Find Nodes?
    Voting Booth?