简体   繁体   English

如何使用 Python 和 PyGTK/PyGDK 在某个 X、Y position 处获得 window?

[英]How can I get the window at a certain X, Y position with Python and PyGTK/PyGDK?

So, I develop a small screenshot utility called Lookit, and I'm wanting to have the user be able to screenshot an entire window (currently entire screen and dragged rectangle capture are supported).因此,我开发了一个名为 Lookit 的小型截图实用程序,我希望用户能够截图整个 window(目前支持整个屏幕和拖动的矩形捕获)。

What I'm wondering is how to get the Window that the user clicks on so that I can find it's geometry and grab that section of the screen.我想知道的是如何获得用户单击的 Window 以便我可以找到它的几何形状并抓住屏幕的那个部分。

Any help is appreciated.任何帮助表示赞赏。

Thanks!谢谢!

Those windows belong to other processes, so you have to go through the windowing system.那些 windows 属于其他进程,所以你必须通过窗口系统来 go。 This is different for each platform, and AFAIK not abstracted by GDK.这对于每个平台都是不同的,并且 AFAIK 不是由 GDK 抽象的。

On X11 you could use the python bindings to libwnck :在 X11 上,您可以使用 python 绑定到libwnck

import wnck
screen = wnck.screen_get_default()
for window in reversed(screen.get_windows_stacked()):
    if window.get_geometry() <matches your click coordinates>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM