dum*_*ter 5 python gtk pygtk pygobject gtk3
我一直在使用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()
Run Code Online (Sandbox Code Playgroud)
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()
Run Code Online (Sandbox Code Playgroud)
当我单击PyGObject版本中的按钮时,不会引发另一个窗口,我收到此错误:
Traceback (most recent call last):
File "test4.py", line 4, in raise_window
w2.window.show()
AttributeError: 'Window' object has no attribute 'window'
Run Code Online (Sandbox Code Playgroud)
所以我想在PyGObject中必须有其他方法来获取Gdk.window?
或者是否有一些不同/更好的方法来实现同一目标?
有任何想法吗?
如该解释后,有两种选择:
临时抬起窗户(可能是你正在寻找的):
def raise_window(widget, w2):
w2.present()
Run Code Online (Sandbox Code Playgroud)
永久提升窗口(或直到通过配置明确更改):
def raise_window(widget, w2):
w2.set_keep_above(True)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3045 次 |
| 最近记录: |