[英]How can I list all open (X11) windows on Gnu/Linux from a Python script?
I'd like to be able to grab a list of all windows that are open on a Linux desktop from a Python script. 我希望能够从Python脚本中获取在Linux桌面上打开的所有窗口的列表。 I suppose this would require working through Xlib or some other x11 or xdisplay library. 我想这将需要通过Xlib或其他x11或xdisplay库进行工作。 This would be the Linux equivalent on win32's EnumWindows API call. 这将等同于Win32的EnumWindows API调用上的Linux。
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? 是否有一些来自Python的函数调用会返回此信息?
Install python-xlib
: 安装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. query.children
是Window
对象的列表,因此对这些对象的一些研究应该会有所作为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.