4

When GetWindowRect() is called in Python, the values it returns are inaccurate if a DPI scaling level of anything but 100% is used. Is there any way to get around this, or mathematically adjust?

jezza
  • 111
  • 1
  • 1
  • 10

1 Answers1

8

You can make your program DPI aware using windll from ctypes:

from ctypes import windll

# Make program aware of DPI scaling
user32 = windll.user32
user32.SetProcessDPIAware()

From that point on calls like GetWindowRect() should return the proper values. I stumbled upon this solution a while back trying to get Pyautogui to give me proper screenshots.

Mike Souder
  • 421
  • 4
  • 7