[pygtk] changing the foreground colour of entry box dynamically
Alessandro Dentella
sandro at e-den.it
Thu Apr 9 15:16:57 WST 2009
On Thu, Apr 09, 2009 at 10:36:18AM +1200, Tim Evans wrote:
> Tim Evans wrote:
> > ganesh gajare wrote:
> >> Hello,
> >> I have created an entry box widget using glade.
> >> and I am doing validation on that field...
> >> So whenever an invalid text is entered in the entry box,the text color
> >> of entry should change dynamically..
> >
> > I haven't tested this, but the method 'modify_text' should do what you
> > need. For example, to set the text to red, use:
> >
> > entry.modify_text(gtk.gdk.color_parse('red'))
> >
> > and to set it back to the default black:
> >
> > entry.modify_text(None)
> >
>
> Well, that's what I get for not even checking the documentation before
> posting. I forgot the first argument to 'modify_text' should be a state
> value. The relevant states here are:
>
> - gtk.STATE_NORMAL for unselected text
> - gtk.STATE_SELECTED for selected text when the entry is focused
> - gtk.STATE_ACTIVE for selected text when a different widget is focused
In case you need to change the background too, i tryed to use modify_bg with
no luck while modify_base just works. I have not understood which is the
difference between one and the other, not I could find an explanation
of the difference between modify_bg and modify_text. The second works to
modify the text of an entry, the first does not.
Any one can explain or pint to documentaion on the difference between
base/bg and text/fg?
In the kiwi package there is an interesting validation field that uses also
images as background. I wanted to do the same but didn't manage missing a
simpler example...
sandro
More information about the pygtk
mailing list