使用 Python 和 Xorg 获取当前窗口标题
在 stackoverflow 回答了我之前关于 Wiimote 左/右键单击问题的问题后,我不仅可以移动鼠标光标,现在还可以左/右键单击事物。我现在还有一个问题。
我在 python 中使用什么来获取当前活动窗口的标题?在谷歌搜索“X11 Python Window Title”、“Linux Python Window Title”和类似内容之后,我发现的只是 win32 和 tkinker (又?),这不是我需要的。
如果你能帮忙,那就太好了!
After stackoverflow answered my previous question on here about my Wiimote left/right click issue, Not only can I move the mouse cursor, I can now left/right click on things. I now have one more question.
What do I use in python to get the title of the current active window? After googling 'X11 Python Window Title', 'Linux Python Window Title' and things similar, All I've found is win32 and tkinker (again?), which isn't what I need.
If you could help, That would be awesome!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
编辑
最佳方法:
替代方法:
EDIT
best way:
Alternative way:
我注意到 wnck 需要 GTK 事件循环来更新活动窗口。 Xlib则不存在这样的问题:
I noticed that wnck requires GTK event loop to update the active window. There is no such problem with Xlib:
Killown 的基于 xprop 的解决方案可以压缩为单个(虽然很长)语句:
killown's xprop-based solution can be compacted into a single (though lengthy) statement:
使用
ewmh
:With
ewmh
:我认为如果你想处理 Windows 和 Windows,python-wnck 可能会很有用。工作区和这样的。我无法立即找到 Python 文档,但根据它包装的 libwnck C 库的文档,它有一个 wnck_screen_get_active_window() 方法。
I think python-wnck might be useful if you want to handle Windows & workspaces & such. I can't find the Python docs immediately, but according to the docs for the libwnck C library that it wraps, it has a wnck_screen_get_active_window() method.
我的解决方案:
My solution:
问题是找出哪个窗口是活动的或者标题是什么?
获取窗口的标题很容易:
,其中 MainWindow 是窗口的名称。但不知道活动窗口。从来没有多个窗口。
Is the problem to find out which window is active or what the title is?
Getting a window's title is easy:
,where MainWindow is the window's name. No idea about active window though. Never had multiple windows.