问题
I have a gtk.Window
. How do I set it to be the active window? I can call is_active()
to see whether it already is, but I don't see where to make it active.
Bonus points: given a gtk.Widget
, how do I make the window it is a part of the active window?
回答1:
Ah thanks to this thread, the answer is to call gtk.Window.present()
.
回答2:
if W
is a gtk.Window
:
import wnck
wnck.window_get(W.window.xid).activate()
回答3:
Here's what worked for me (thanks Dan D for pointing out wnck)
def activate(window):
screen = wnck.screen_get_default()
screen.force_update()
wnckwin = [win for win in screen.get_windows() if win.get_xid() == window.window.xid][0]
wnckwin.activate(gtk.gdk.x11_get_server_time(window.window))
回答4:
You can also use gtk.Dialog.run
(if it's a Dialog) aditional to gtk.Window.present
来源:https://stackoverflow.com/questions/5393185/gtk-set-active-window