[pygtk] gtk.STATE_PRELIGHT

John Finlay finlay at moeraki.com
Fri Apr 28 03:40:55 WST 2006


Sandro Dentella wrote:
> Hi all,
>
>   is there anythig wrong with this way of using PRELIGHT? I would imagine
>   the label to change fg to RED when the mouse is over it... but I may have
>   misunderstood the manual...
>
> RED = gtk.gdk.color_parse('red')
> BLU = gtk.gdk.color_parse('blue')
>   
You will also have to allocate the colors using the 
gtk.gdk.Colormap.alloc_color() method
> w = gtk.Window()
> v = gtk.VBox()
> E = gtk.EventBox()
> l = gtk.Label("LABEL")
>
> l.modify_fg(gtk.STATE_NORMAL, BLU)
> l.modify_fg(gtk.STATE_PRELIGHT, RED)
>
> w.add(v)
> v.add(E)
> E.add(l)
> w.show_all()
>
>   
In addition I think you have to catch the enter and leave notify events 
on the EventBox and set the state of the Label accordingly. For example 
something like:

def ene_cb(eb, ev):
  eb.get_child().set_state(gtk.STATE_PRELIGHT)
  return True

def lne_cb(eb, ev):
  eb.get_child().set_state(gtk.STATE_NORMAL)
  return True

E.connect('enter-notify-event', ene_cb)
E.connect('leave-notify-event', lne_cb)

might work for you.

John


More information about the pygtk mailing list