6

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 を取得する他の方法があるに違いないと思いますか?

または、同じ目標を達成するための別の/より良い方法はありますか?

何か案は?

4

3 に答える 3

8

この投稿で説明されているように、2 つのオプションがあります。

ウィンドウを一時的に上げます(おそらくあなたが探しているものです):

def raise_window(widget, w2):
    w2.present()

ウィンドウを永続的に (または構成によって明示的に変更されるまで) 上げます。

def raise_window(widget, w2):
    w2.set_keep_above(True)
于 2012-01-29T16:29:43.067 に答える