rbc has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I would like to be able to draw things (rectangles, lines, ...) on a Tk::Canvas and be able to specify the color with an integer that would correspond to the "color palette" like so ...
$can->create ( 'rectangle', $X, $Y, $X+1, $Y+1, -fill => 1 );
... this of course does not work one must specify a color with a string like 'red' or 'blue'. I guess my question is ... Can I access the color palette directly in Perl/Tk? thanks

Replies are listed 'Best First'.
Re: Tk::Canvas colors
by kvale (Monsignor) on Jun 21, 2002 at 02:14 UTC
    One method is simply to create an array with color names and use that in palce of integers:
    @color = qw|red green blue|; $can->create ( 'rectangle', $X, $Y, $X+1, $Y+1, -fill => $color[1]; );
    To set your whole application to a consistent color, use
    $widget->setPalette('red');
    You can also the hex values in place of a color name:
    ($r, $g, $b) = $widget->rgb("red"); $hex_color = "$r$g$b$"; $mw->Button( -background => $hexcolor);

    -Mark
Re: Tk::Canvas colors
by caedes (Pilgrim) on Jun 21, 2002 at 02:14 UTC
    Apparently you can use any color definition format that the Tk_GetColor procedure will accept.

    -caedes

Re: Tk::Canvas colors
by rbc (Curate) on Jun 21, 2002 at 19:17 UTC
    Thanks! kvale and caedes that help me write
    a mandelbrot Perl/Tk program.

    Why not check it out 176202
      There are never enough Mandelbrot programs! Rock on!!! :-)

      -caedes