InterviewSolution
| 1. |
How Do I Change The Colour Of A Widget (or How Do I Get A Gdkcolor)? |
|
Answer» There is some confusion about GDKCOLOR and how it is created. There are both the GdkColor() class and colour_alloc() that seem to do the right thing, but they are both duds (as far as I can tell). The right way of creating a colour is getting the colormap from the widget and using it to allocate a new colour using the GtkColorMap's ALLOC method: E = gtk.ENTRY() This way you end up with a red GdkColor in the variable colour. Apart from the X11 rgb.txt names, you can also use hex triplets: colour = map.alloc_color("#FF9999") # light red The next step is understanding how to manipulate GtkStyle's colour attributes, which are actually dictionaries: each attribute maps a number of different gtk constants that indicate states:
So, to change the default border of our entry above to red: style = e.get_style().copy() Final hint: the default colour for a GtkEntry background is gray84. There is some confusion about GdkColor and how it is created. There are both the GdkColor() class and colour_alloc() that seem to do the right thing, but they are both duds (as far as I can tell). The right way of creating a colour is getting the colormap from the widget and using it to allocate a new colour using the GtkColorMap's alloc method: e = gtk.Entry() This way you end up with a red GdkColor in the variable colour. Apart from the X11 rgb.txt names, you can also use hex triplets: colour = map.alloc_color("#FF9999") # light red The next step is understanding how to manipulate GtkStyle's colour attributes, which are actually dictionaries: each attribute maps a number of different gtk constants that indicate states: So, to change the default border of our entry above to red: style = e.get_style().copy() Final hint: the default colour for a GtkEntry background is gray84. |
|