asweigart / PyGetWindow

A simple, cross-platform module for obtaining GUI information on applications' windows.
BSD 3-Clause "New" or "Revised" License
362 stars 69 forks source link

PyGetWindow returns wrong location #26

Open swadeeshs opened 4 years ago

swadeeshs commented 4 years ago

Here is my simple code to locate the Notepad++ opened on my screen. (Windows10) import pygetwindow window_name = 'new 1 - Notepad++' window = pygetwindow.getWindowsWithTitle(window_name)[0] print(window.topleft) Output when executed>>Point(x=830, y=250)

The same code returns a different set of coordinates when I import PyAutoGUI. Here is the code and the output. import pygetwindow import pyautogui window_name = 'new 1 - Notepad++' window = pygetwindow.getWindowsWithTitle(window_name)[0] print(window.topleft) Output when executed>>Point(x=1038, y=312)

Martyn0324 commented 3 years ago

Hey! I was having a similar issue, but not only with PyGetWindow but also with win32gui from pywin32.

I was trying to extract a game window size, which I know for sure it's more or less width=1015 and height=678 (I used a sprite extractor). However, PyGetWindow was returning width=821 and height=572, while win32gui was returning width=816 and height=544.

Upon seeing your issue, I installed pyautogui and imported it. Then PyGetWindow started to return width = 1026 and height = 715, while win32gui returned width=1020 and height = 680.

There might be a bug within PyGetWindow and win32gui that is fixed with the installation of pyautogui or some of its complements.

The code:

import pyautogui
import pygetwindow

teste = pygetwindow.getWindowsWithTitle('Jigoku Kisetsukan: Sense of the seasons v.1.09')[0]

print(teste.size)

import win32gui

window = win32gui.FindWindow(None, 'Jigoku Kisetsukan: Sense of the seasons v.1.09')

A screenshot of the situation, in case someone gets curious: PS: The screenshot was taken before the fix. I took it to use it in my sprite extractor. Teste