views:

56

answers:

1

Various examples always use alloc_color() and stuff like gtk.color.parse('red'), etc. I just do gtk.gdk.Color(65535,0,0), and that seems to work. What's the need for alloc_color?

+2  A: 

If you're running on a system that uses a palette display (as opposed to a true-colour display), then you must allocate new colours in the palette before you can use them. This is because palette-based displays can only display a limited number of colours at once (usually 256 or sometimes 65536).

Most displays these days are capable of true colour display, which can display all available colours simultaneously, so this won't appear to be a problem and you can get away with directly asking for specific colours.

Greg Hewgill
does it allocate a best-matching color if run in a 256 or 16-bit color mode?
Claudiu
(my point is: if it does, I don't see why I have to do it explicitly. If it doesn't - why not? that would clearly be my intention)
Claudiu
That depends on the particular graphics library. I'm not familiar enough with GTK to say whether `alloc_color()` does any matching.
Greg Hewgill