views:

164

answers:

1

Hi,

I'm trying to create a PyGTK StatusIcon with transparent background. I need to draw the contents of the StatusIcon at runtime.

StatusIcon wants a Pixbuf object (which can have transparency). No problem with that:

pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, width, height)
pixbuf.fill(0xffffffff)

The problem is, I can't draw to Pixbuf objects. My current approach is to draw to a Pixmap and then convert it to a Pixbuf, but unfortunately Pixmaps can't have transparency.

How do I get a Pixbuf with transparent background that I can draw at runtime?

Greets, Philip

A: 

You can add transparency to Pixbuf objects with the add_alpha() method. The following line will set zero opacity for the color #ffffff:

pixbuf = pixbuf.add_alpha(True, 0xFF, 0xFF, 0xFF)

Too easy... :-|

Philip