JavaScript EditorFree JavaScript Editor     Perl Manuals 



Main Page

13.4. Color-Related Methods

There are four methods that deal with color: colormapfull, rgb, cells, and depth. They are described in the following sections.

13.4.1. Is the Colormap Full?

To determine if the colormap for the widget is full, use colormapfull:

$isfull = $widget->colormapfull;

The colormapfull method returns a 1 if the colormap is full and 0 if it is not full.

13.4.2. Cell Count

The number of cells in the colormap can be obtained by using the cells method:

$count = $widget->cells;

The value returned is a number indicating the number of colors; for example, 64.

13.4.3. Color Depth

You can get the number of bits per pixel by using the depth method:

$depth = $widget->depth;
# $depth might contain "16"

13.4.4. Translate to RGB Value

You can translate a color name to the red, green, and blue values by using the rgb method. Send rgb a color name and it returns a list containing three items that represent the red, green, and blue numbers.

($red, $green, $blue) = $widget->rgb("color");

Now $red, $green,and $blue each contain an integer from to 2n-1, where n is the number of bit planes in your display. For 8-bit color, the maximum value is 255 (0xFF); for 16-bit color, it's 65,535 (0xFFFF).

When specifying a hexadecimal color, feel free to over-specify the value. For instance, if you want the color red, use 0xFFFF00000000. Tk will use it if possible, or will down-convert it to 0xFF0000 for an 8-bit display.

13.4.5. Setting Colors

You can have your entire application based on one color automatically by using the setPalette method:

$widget->setPalette(color);

The background color of $widget is set to the specified color, and the colors for all other widgets are calculated based on that color. So if a Button's edge is a lighter color than the background, it will show up a lighter shade of whatever color you pick. This method affects the entire application even if you only call it on a widget instead of a Toplevel.

You can set colors for explicit options by specifying the name and then the color to associate with it. For instance, the following code will set all foreground items in the application to red and all background items to blue:

$b->setPalette(background => "blue", foreground => "red");

Note that this is the only widget we know of where you cannot use a leading dash for an option.

13.4.6. Predefined Color Scheme

The bisque method sets the entire application to use a bisque scheme, the original Tcl color. Calling $widget->bisque is the same as calling $widget->setPalette("bisque"). This is the only predefined color scheme, mainly for Tcl old-timers who remember the days before the new steel scheme was voted in.






JavaScript EditorJavaScript Formatter     Perl Manuals


©