我如何引发一个最小化或被PyGObject覆盖的窗口?

问题描述 投票:5回答:3

我一直在使用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?

或者是否有一些不同/更好的方法来实现相同的目标?

有什么想法吗?

python gtk pygtk gtk3 pygobject
3个回答
7
投票

3
投票

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.