Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning all desktop windows with PyWinAuto

I am trying to return all windows from my machine using PyAutoWin. The ultimate goal is to later narrow down this list to a subset of windows to automate (resize and perform scraping actions) using a mixture of methods.

However I am failing at the most basic task: returning all windows. My code is:

import pywinauto

print(pywinauto.findwindows.enum_windows())

and getting this error:

Traceback (most recent call last):
  File "app.py", line 4, in <module>
    print(pywinauto.findwindows.enum_windows())
  File "C:\Users\*\.virtualenvs\scraper-j58Iv-wO\lib\site-packages\pywinauto\findwindows.py", line 368, in enum_windows
    win32functions.EnumWindows(proc, 0)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: expected WinFunctionType instance instead of WinFunctionType

I tried instantiating a Desktop() object and passing it to the enum_windows() method but it does not take in argument.

Any help is greatly appreciated!

Best regards

like image 256
fisheatshark Avatar asked Sep 06 '25 20:09

fisheatshark


1 Answers

The right way to do that:

from pywinauto import Desktop
top_windows = Desktop(backend="uia").windows() # or backend="win32" by default

# walk the returned list of wrappers
for w in top_windows:
    print(w.window_text())
like image 123
Vasily Ryabov Avatar answered Sep 08 '25 09:09

Vasily Ryabov