【发布时间】:2011-10-28 13:45:41
【问题描述】:
我有一个使用 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(最近一次调用最后一次):文件“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() argument 1 must be gtk.gdk.Colormap, not 无
快速“打印 rgba”确认 rgba 为“无”,因此出现错误。
UBUNTU“ONERIC OCELOT”运行:
Gtk 警告:尝试将深度为 24 的可绘制对象绘制为深度为 32 的可绘制对象
发生了什么事?我迫切需要窗口的透明背景。
【问题讨论】:
标签: window transparency pygtk cairo rgba