如何打开最小化或被 PyGObject 覆盖的窗口?
我一直在使用 PyGTK FAQ 中提供的答案,但这似乎并不使用 PyGObject。为了您的方便,这里有一个适用于 PyGTK 的测试用例,以及一个不适用于 PyGObject 的翻译版本。
PyGTK 版本:
import gtk
def raise_window(widget, w2):
w2.window.show()
w1 = gtk.Window()
w1.set_title('Main window')
w2 = gtk.Window()
w2.set_title('Other window')
b = gtk.Button('Move something on top of the other window.\nOr, minimize the'
'other window.\nThen, click this button to raise the other'
'window to the front')
b.connect('clicked', raise_window, w2)
w1.add(b)
w1.show_all()
w2.show_all()
w1.connect('destroy', gtk.main_quit)
gtk.main()
PyGObject 版本:
from gi.repository import Gtk
def raise_window(widget, w2):
w2.window.show()
w1 = Gtk.Window()
w1.set_title('Main window')
w2 = Gtk.Window()
w2.set_title('Other window')
b = Gtk.Button('Move something on top of the other window.\nOr, minimize the'
'other window.\nThen, click this button to raise the other'
'window to the front')
b.connect('clicked', raise_window, w2)
w1.add(b)
w1.show_all()
w2.show_all()
w1.connect('destroy', Gtk.main_quit)
Gtk.main()
当我单击 PyGObject 版本中的按钮时,不会引发另一个窗口,并且出现此错误:
Traceback (most recent call last):
File "test4.py", line 4, in raise_window
w2.window.show()
AttributeError: 'Window' object has no attribute 'window'
所以我猜一定有其他方法可以获取 PyGObject 中的 Gdk.window?
或者是否有一些不同/更好的方法来实现相同的目标?
有什么想法吗?
I'd been using the answer provided in the PyGTK FAQ, but that doesn't seem to work with PyGObject. For your convenience, here is a test case that works with PyGTK, and then a translated version that doesn't work with PyGObject.
PyGTK Version:
import gtk
def raise_window(widget, w2):
w2.window.show()
w1 = gtk.Window()
w1.set_title('Main window')
w2 = gtk.Window()
w2.set_title('Other window')
b = gtk.Button('Move something on top of the other window.\nOr, minimize the'
'other window.\nThen, click this button to raise the other'
'window to the front')
b.connect('clicked', raise_window, w2)
w1.add(b)
w1.show_all()
w2.show_all()
w1.connect('destroy', gtk.main_quit)
gtk.main()
PyGObject version:
from gi.repository import Gtk
def raise_window(widget, w2):
w2.window.show()
w1 = Gtk.Window()
w1.set_title('Main window')
w2 = Gtk.Window()
w2.set_title('Other window')
b = Gtk.Button('Move something on top of the other window.\nOr, minimize the'
'other window.\nThen, click this button to raise the other'
'window to the front')
b.connect('clicked', raise_window, w2)
w1.add(b)
w1.show_all()
w2.show_all()
w1.connect('destroy', Gtk.main_quit)
Gtk.main()
When I click the button in the PyGObject version, the other window isn't raised, and I get this error:
Traceback (most recent call last):
File "test4.py", line 4, in raise_window
w2.window.show()
AttributeError: 'Window' object has no attribute 'window'
So I guess there must be some other way to get the Gdk.window in PyGObject?
Or is there some different/better way of accomplishing the same goal?
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如这篇帖子中所解释的,有有两个选项:
暂时升起窗口(可能是您正在寻找的):
永久升起窗口(或直到通过配置显式更改):
As explained in this post, there are two options:
Raise the window temporarily (probably what you're looking for):
Raise the window permanently (or until explicitly changed by configuration):
present
对我来说暂时加薪不起作用,但这确实有效:present
didn't work for me for a temporary raise, but this did:这对我来说最有效:
在应用程序启动时将窗口置于前面,然后
使用它们正常运行是行不通的
This is what works best for me:
To bring window to front when the application start and then behave normally
using these won't work