简体   繁体   English

如何通过Python脚本列出Gnu / Linux上的所有打开(X11)窗口?

[英]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.childrenWindow对象的列表,因此对这些对象的一些研究应该会有所作为。

Window object docs . Window对象文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Python 脚本列出 Mac 上所有打开的窗口? - How can I list all open windows on Mac from a Python script? 在没有显式打开X11的情况下启动Python脚本 - Starting Python script without explicitly having X11 open 无法从 VSCode 终端打开 X11 Windows - Unable to open X11 Windows from VSCode terminal Windows中的Python和X11连接 - Python and X11 connection in windows Python 如何访问 X11 剪贴板? - How can Python access the X11 clipboard? 如何在python环境中将x11()用于rpy2? - how can I get x11() available for rpy2 in python environment? 如何从列表= ['\\ xbb','\\ x02','\\ x00','\\ x11','\\ xbe']中删除“ \\ x” - How to remove '\x' from list =[ '\xbb', '\x02', '\x00', '\x11', '\xbe'] 如何“锁定键盘”以防止在X11 / Linux / Gnome上发送更多按键? - How do I 'lock the keyboard' to prevent any more keypresses being sent on X11/Linux/Gnome? 如何移动或调整X11窗口的大小(即使它们最大化)? - How to move or resize X11 windows (even if they are maximized)? 如何将 Python / Kivy 程序从使用 X11 转换为使用帧缓冲区(从 Window 到 Kiosk 操作) - How to convert Python / Kivy program from using X11 to using framebuffer (from Window to Kiosk operation)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM