在python中获取活动的gtk窗口 [英] Get active gtk window in python
问题描述
我如何在python中获取活动的 gtk.Window
的句柄?(不是我创建的窗口,而是当前聚焦的窗口).
How would I get a handle to the active gtk.Window
in python? (not a window I created, but the currently focused window).
推荐答案
答案实际上不是特定于操作系统的,您可以在GTK中完成.您可以使用 gtk.window_list_toplevels()
从应用程序中获取所有顶级窗口的列表,然后对其进行迭代,直到找到 window.is_active()
返回 True
.
The answer is actually not OS-specific -- you can do it within GTK. You can get a list of all the toplevel windows from the application using gtk.window_list_toplevels()
, then iterate through it until you find one where window.is_active()
returns True
.
如果您要考虑应用程序之外的其他窗口,则可以尝试 gtk.gdk.screen_get_default().get_toplevel_windows()
,但这只会为您提供GDK窗口,而不是GTK窗口,因为您无法知道这些GDK窗口是否实际上与GTK窗口相关联.
If you want to consider other windows than the ones from your application, then you could try gtk.gdk.screen_get_default().get_toplevel_windows()
but this will only get you GDK windows and not GTK windows, because you have no way of knowing whether those GDK windows are actually associated with GTK windows.
这篇关于在python中获取活动的gtk窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!