dieki
dieki

Reputation: 2475

Setting opacity on a PyGTK label

Is there a way to make a PyGTK widget partly transparent, so that the widgets behind it can be seen through it? Specifically I'm trying to do this on a label, for typographic effect; I don't want to change the color instead, as it may not look right on all themes.

Upvotes: 0

Views: 848

Answers (1)

user319799
user319799

Reputation:

No, not possible. It is possible to make entire windows partially transparent, if window manager supports compositing, but not individual widgets.

I guess what you want can be achieved differently by "blending" colors:

def blend (color1, color2, weight = 0.5):
    return gtk.gdk.Color (
        color1.red_float   * weight + color2.red_float   * (1 - weight),
        color1.green_float * weight + color2.green_float * (1 - weight),
        color1.blue_float  * weight + color2.blue_float  * (1 - weight))

for state in gtk.StateType.__enum_values__:
    label.modify_fg (state, blend (label.style.fg[state], label.style.bg[state]))

To make it completely correct you can also listen to "style-set" signal.

Upvotes: 2

Related Questions