通过Python发现在Gnome/Linux/Ubuntu上活动的窗口是什么? [英] Discover what window is active on Gnome/Linux/Ubuntu from Python?

查看:292
本文介绍了通过Python发现在Gnome/Linux/Ubuntu上活动的窗口是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以获取当前打开的所有窗口的列表,并查看Python顶部的窗口(即活动窗口?)?

Is there any way to get a list of all windows that are open at present and see what window is at the top (i.e. active?) from Python?

这是在Ubuntu Linux上使用的Gnome.

This is using Gnome on Ubuntu Linux.

wnck看起来可能会这样做,但是在文档中却非常缺乏.

wnck looks like it might do this, but it's very lacking in documentation.

推荐答案

import wnck
screen = wnck.screen_get_default()
window_list = screen.get_windows()
active_window = screen.get_active_window()

另请参见在X中获取活动窗口标题,并在文档.其他包含wnck的问题具有有用的代码示例.

See also Get active window title in X, and WnckScreen in the documentation. Other questions containing wnck have useful code samples.

这篇关于通过Python发现在Gnome/Linux/Ubuntu上活动的窗口是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆