简体   繁体   中英

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).

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.

Any help is appreciated.

Thanks!

Those windows belong to other processes, so you have to go through the windowing system. This is different for each platform, and AFAIK not abstracted by GDK.

On X11 you could use the python bindings to libwnck :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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