4

Python 2.7 と PyGTK のプロジェクトがあります。

透明な背景ウィンドウを作成する必要がありますが、ウィンドウ内に画像 (ピックスマップおよびマスク ベース) やその他のオブジェクトを表示できます。

次のコードを使用していますが、Ubuntu (Oneric Ocelot) に画像オブジェクトが表示されず、以下に投稿されたエラーが表示されます (ウィンドウにはボタン オブジェクトが表示されます)。これは Windows 7 でもレンダリングされません (このエラーは以下にも掲載されています)。

def expose(widget, event):
            cr = widget.window.cairo_create()

            # Sets the operator to clear which deletes everything below where an object is drawn
            cr.set_operator(cairo.OPERATOR_CLEAR)
            # Makes the mask fill the entire window
            cr.rectangle(0.0, 0.0, *widget.get_size())
            # Deletes everything in the window (since the compositing operator is clear and mask fills the entire window
            cr.fill()
            # Set the compositing operator back to the default
            cr.set_operator(cairo.OPERATOR_OVER)

        hab_fish_win = gtk.Window()
        hab_fish_win.resize(640, 480)
        hab_fish_win.set_resizable(False)
        hab_fish_win.set_decorated(False)
        hab_fish_win.set_has_frame(False)
        hab_fish_win.set_position(gtk.WIN_POS_CENTER)
        hab_fish_win.set_app_paintable(True)
        screen = hab_fish_win.get_screen()
        rgba = screen.get_rgba_colormap()
        hab_fish_win.set_colormap(rgba)
        hab_fish_win.connect('expose-event', expose)

        hab_fish_win.show()

ウィンドウズ 7 ラン:

トレースバック (最後の最後の呼び出し): ファイル "C:\Users\user\MousePaw Games\Word4Word\PYM\fishtest2.py"、337 行目、HAB_FISH() ファイル "C:\Users\user\MousePaw Games\Word4Word\ PYM\fishtest2.py"、100 行目、init hab_fish_win.set_colormap(rgba) TypeError: Gtk.Widget.set_colormap() 引数 1 は、None ではなく gtk.gdk.Colormap でなければなりません

簡単な「print rgba」は、rgba が「None」であることを確認するため、エラーになります。

UBUNTU「ONERIC OCELOT」実行:

Gtk 警告: 深さ 24 のドローアブルを深さ 32 のドローアブルに描画しようとしています

何が起こっている?ウィンドウの透明な背景がどうしても必要です。

4

1 に答える 1

3

さて、何時間もの調査の結果、Windows はこの種の透過性をサポートしていないことがわかりました。Linux のエラーについては、わかりません。

私は PyGObject に移植しており、目的のために別の方法を使用しています。この回答の読者は、それを調べることをお勧めします。

于 2011-10-28T05:45:41.063 に答える