zentara wrote:
On Tue, 26 Aug 2008 18:09:58 +0100, [EMAIL PROTECTED] (Aruna Goke)
wrote:
I am writing a raffle draw promo using perl and i have the script as below.
what i intend to achieve is to print all the numbers in the array to gui
screen, clear the screen and display randomly selected one as the winner.
however, I have run my script in the cmd line .. it works fine but I
need a colorful GUI to do that.
Can someone guide me on where i can get a solution to it?
I have laid my hand on wxperl but unable to print it.
Best GUI? This is easily portable between linux and Windows.
Here is a Tk Canvas script that will do it.
Left mouse click on the canvas will show the winner.
#!/usr/bin/perl -w
use warnings;
use strict;
use Tk;
# put in your row and columns size
my( $x,$y) = (10,10);
my $winner = int rand($x * $y);
#print "$winner\n";
my $mw = MainWindow->new;
my $vh = $mw->vrootheight;# -100; #get window full size
my $vw = $mw->vrootwidth;# -100; #with some margin maybe
my $xsize = $vw/$x; #cell sizes
my $ysize = $vh/$y;
$mw->fontCreate('big',
-family=>'arial',
-weight=>'bold',
-size=> 38
);
# this is what grabs all virtual desktops
#$mw->overrideredirect(1);
# Note that the 'virtual window' height and width are $vh and $vw
# respectively, so we use those dimensions for our Canvas height
# and width, and let the Canvas expand and fill in both x and y
# directions.
#
my $c = $mw->Canvas(
-width => $vw,
-height => $vh,
-background =>'black',
#-takefocus =>0
)->pack(-expand => 1, -fill => 'both');
my %cell;
my $count = 0;
my $xdelta;
my $ydelta;
for my $xc(0..$x-1) {
for my $yc(0..$y-1){
$count++;
if($count == $winner){
$cell{$xc}{$yc}{'win'} = $c->createText(
$xc * $xsize + $xsize/2,
$yc* $ysize + $ysize/2,
-anchor=>'center',
-font => 'big',
-fill => 'red',
-text => 'WIN',
-tags => ['winner']
);
$c->lower( 'winner' ,'rect' );
}
$cell{$xc}{$yc}{'rect'} =
$c->createRectangle($xc * $xsize, $yc* $ysize ,
$xc * $xsize + $xsize ,$yc* $ysize +
$ysize ,
-fill=> 'lightyellow',
-outline=>'black',
-tags => ['rect']
);
$cell{$xc}{$yc}{'text'} = $c->createText(
$xc * $xsize + $xsize/2,
$yc* $ysize + $ysize/2,
-anchor=>'center',
-font => 'big',
-fill => 'black',
-text => $count,
-tags => ['rect']
);
}
}
$c->CanvasBind("<Button-1>", sub{
$c->raise( 'winner' ,'rect' );
});
MainLoop;
__END__
zentara
Thanks Zentara for this wonderful piece.
I will work on it and see how i can modify it to meet my need. you make
me happy.. thanks
Goksie
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/