I'd like to be able to grab a list of all windows that are open on a Linux desktop from a Python script. I suppose this would require working through Xlib or some other x11 or xdisplay library. This would be the Linux equivalent on win32's EnumWindows API call.
Ideally, I'd like to be able to use this to get a list of the title/caption text of every open window along with position/size information.
Is there some function call from Python that will return this info?
Install python-xlib
:
pip3 install python-xlib
Try this:
from Xlib import display
d = display.Display()
root = d.screen().root
query = root.query_tree()
for c in query.children:
# returns window name or None
name = c.get_wm_name()
if name:
print(name)
I'm not sure about the other properties. query.children
is a list of Window
objects, so some research on those should turn up something.
Window
object docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With