For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > March 2005 > Xcolor usage in Perl/Tk ? ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Xcolor usage in Perl/Tk ? ?
Nash Aragam

2005-03-09, 8:57 pm

Hi,

Does anybody know how to declare an Xcolor variable in Perl ? I want to
pass an Xcolor (the hex formatted RGB value) to a CreateLine() method on
a Canvas. Any ideas of how to do that ? Right now, the code fails when I
pass 'ffffffff' as a color value to the CreateLine method...? ?

Any help is highly appreciated...TiA,

Nash
nrg@ornl.gov

Steve Lidie

2005-03-10, 3:59 pm

Nash Aragam <naragam@acm.org> wrote:
> Hi,
>
> Does anybody know how to declare an Xcolor variable in Perl ? I want to
> pass an Xcolor (the hex formatted RGB value) to a CreateLine() method on
> a Canvas. Any ideas of how to do that ? Right now, the code fails when I
> pass 'ffffffff' as a color value to the CreateLine method...? ?
>
> Any help is highly appreciated...TiA,
>
> Nash
> nrg@ornl.gov
>


$c=$mw->Canvas(-bg=> '#ffffff')->pack
zentara

2005-03-10, 3:59 pm

On Wed, 09 Mar 2005 17:33:02 -0500, Nash Aragam <naragam@acm.org> wrote:

>Hi,
>
>Does anybody know how to declare an Xcolor variable in Perl ? I want to
>pass an Xcolor (the hex formatted RGB value) to a CreateLine() method on
>a Canvas. Any ideas of how to do that ? Right now, the code fails when I
>pass 'ffffffff' as a color value to the CreateLine method...? ?
>
>Any help is highly appreciated...TiA,


Prepend a '#' to the hex string.

#!/usr/bin/perl
use warnings;
use strict;
use Tk;

my $mw=new MainWindow;

my $canv =$mw->Scrolled('Canvas',
-width=>200,
-height=>200,
-scrollregion=>[0,0,200,800],
-scrollbars=>'e')
->pack(-fill=>'both',-expand=>1);

for (1..100){
my $color = getcolor();
print "$color\n";
$canv->createLine(int rand 200,int rand 200,
int rand 200,int rand 200,
-fill=>$color,

);
$mw->update;
}

MainLoop;
########################################
#####

sub getcolor{
my($string) = '#';
my($length) = 7;
my(@chars) = ('a' .. 'f', 0 .. 9);
while (length($string) != $length) {
$string .= $chars[ rand($#chars) ];
}
return $string;
}

__END__


--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com