I've got the following running in python 3.9.13
>>>import pyautogui
>>> hwnd = pyautogui.getWindowsWithTitle("Untitled - Notepad")
>>> hwnd2 = pyautogui.getActiveWindow()
>>> hwnd
[Win32Window(hWnd=262986)]
>>> hwnd2
Win32Window(hWnd=461622)
>>> print(hwnd[0])
<Win32Window left="844", top="49", width="379", height="462", title="Untitled - Notepad">
>>> print(hwnd[0].top)
49
>>> print(hwnd[0].left)
844
>>> print(hwnd2[0])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'Win32Window' object is not subscriptable
How do I get at the 'elements' in the hwnd2 (object?)
Look at what print(hwnd2)
prints. hwnd2
is not a list but just the object itself. So why put [0]
behind it? Just access hwnd2
, hwnd2.left
etc.