## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

# Color-Related Methods

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

## 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.

## 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.

## Color Depth

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

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

## 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.

## Setting Colors

You can have your entire application based on one color automatically by using the `setPalette ...`

## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required