The documentation shows that there are five states for a widget[1].
For each state, the GTK theme defines different colours for
background, foreground etc.
You can see some discussion about colours on John Stowers blog[2]. He
has a good screenshot showing the different colours for each state[3],
which makes it easier to find which colour you want to change.
You can directly modify the bg, fg, text, and base colours using the
widget.modify_* functions. For example:
mywidget.modify_bg(gtk.STATE_NORMAL, mycolor)
# if you have a widget which changes appears when
# selected you might have to change the other states as well.
mywidget.modify_bg(gtk.STATE_SELECTED, mycolor)
Here is what I found about the theme guidelines for different colours[4]:
# fg - Sets the foreground color of a widget.
# bg - Sets the background color of a widget.
# text - Sets the foreground color for widgets that have editable text.
# base - Sets the background color for widgets that have editable text.
I only have experience changing the colours for my own custom widgets
which do not to have states like prelight or selected. Let me know if
this works.
Laszlo
[1] http://www.pygtk.org/docs/pygtk/gtk-constants.html#gtk-state-type-constants
[2]
http://www.johnstowers.co.nz/blog/index.php/2008/07/31/conduit-ui-experiments/
[3]
http://www.johnstowers.co.nz/blog/wp-content/uploads/2008/07/theme-swatch.png
[4] http://orford.org/gtk/
On Thu, Apr 9, 2009 at 2:16 AM, Alessandro Dentella wrote:
> 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
> ___
> pygtk mailing list pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>
___
pygtk mailing list pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/