gpt4 book ai didi

python - 如何在 Ubuntu 中获取 PyGTK 或 GTK 中打开的窗口列表?

转载 作者:太空狗 更新时间:2023-10-29 21:13:04 27 4
gpt4 key购买 nike

如何在 PyGTK 或 GTK 或其他编程语言中获取打开的窗口列表?在 Ubuntu 中?

编辑:

我想获取在桌面上打开的目录的列表路径!

最佳答案

欢迎来到 2013 年!下面是使用 Wnck 及其现代 GObject Introspection 库的代码,而不是现在已弃用的 PyGTK 方法。您也可以查看 my other answer about wnck :

from gi.repository import Gtk, Wnck

Gtk.init([]) # necessary only if not using a Gtk.main() loop
screen = Wnck.Screen.get_default()
screen.force_update() # recommended per Wnck documentation

# loop all windows
for window in screen.get_windows():
print window.get_name()
# ... do whatever you want with this window

# clean up Wnck (saves resources, check documentation)
window = None
screen = None
Wnck.shutdown()

至于文档,请查看 Libwnck Reference Manual .它不是特定于 python,但使用 GObject Introspection 的全部意义在于在所有语言中使用相同的 API,这要归功于 gir 绑定(bind)。

此外,Ubuntu 附带了 wnck 及其相应的 gir 绑定(bind),但如果您需要安装它们:

sudo apt-get install libwnck-3-* gir1.2-wnck-3.0

这还将安装 libwnck-3-dev,这不是必需的,但会安装有用的文档,您可以使用 DevHelp 阅读。

关于python - 如何在 Ubuntu 中获取 PyGTK 或 GTK 中打开的窗口列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1380784/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com