16.2. Color-Related Methods
There are four methods that deal with color: colormapfull, rgb, cells, and depth.
16.2.1. Is the Colormap Full?
To determine if the colormap for the widget is full, use colormapfull:
$isfull = $widget->colormapfull();
Thecolormapfull method returns a 1 if the colormap is full and if it is not full.
16.2.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.
16.2.3. Color Depth
You can get the number of bits per pixel by using the depth method:
$depth = $widget->depth(); # $depth might contain "16"
16.2.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 (valid color names were covered in Chapter 3) 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 255.
16.2.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 picked. This method ...
Get Learning Perl/Tk now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.