[pygtk] changing the foreground colour of entry box dynamically

Tim Evans t.evans at aranz.com
Thu Apr 9 06:36:18 WST 2009


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

-- 
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/


More information about the pygtk mailing list