window - 在 PyGTK 中创建 RGBA 颜色图

标签 window transparency pygtk cairo rgba

我有一个使用 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()

Windows 7 运行:

Traceback (most recent call last): File "C:\Users\user\MousePaw Games\Word4Word\PYM\fishtest2.py", line 337, in HAB_FISH() File "C:\Users\user\MousePaw Games\Word4Word\PYM\fishtest2.py", line 100, in init hab_fish_win.set_colormap(rgba) TypeError: Gtk.Widget.set_colormap() argument 1 must be gtk.gdk.Colormap, not None

快速“print rgba”确认 rgba 为“None”,因此出现错误。

UBUNTU“ONERIC OCELOT”运行:

Gtk Warning: Attempt to draw a drawable with depth 24 to a drawable with depth 32

这是怎么回事?我非常需要窗口的透明背景。

最佳答案

好吧,经过几个小时的研究,我发现 Windows 不支持这种透明度。至于Linux的错误,我不知道。

我正在移植到 PyGObject,并使用另一种方法来达到目的。我建议这个答案的读者仔细研究一下。

关于window - 在 PyGTK 中创建 RGBA 颜色图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7831106/

相关文章:

python - pygtk:确定键是修饰符

javascript - setInterval/setTimeout 可能会导致页面重新加载

用于卸载库的 Windows API

matplotlib - matplotlib 可以生成 EPS10 输出吗?

ios - 透明 View 背景变黑

python - pygtk 从父节点按名称获取小部件

python gtk gobject 切换窗口的可见性

window - 如何终止 tmux 中的窗口?

C# 获取焦点窗口?

ios - UIView 背景颜色和顶部透明png