zentara wrote:
On Tue, 26 Aug 2008 18:09:58 +0100, [EMAIL PROTECTED] (Aruna Goke)
wrote:

...............................

__END__

zentara


Thanks Zentara,

I have edited the code as below.. however, I wanted to be able to scroll both horizontally and vertically so that i can see all the numbers printed. and which one is selected as winner on click.

and ability to click and randomly selected a single winner as long as i click will be appreciated.

Thanks for the code.. though i have spent time on Wxperl without good result..
It saved me a lot.

thanks

goksie


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

#generate the size of an my array.

my $filename = "C:\\jointcodes\\julypromo.csv";
#Open the file
open FH, '<', $filename || die "Couldn't open $filename : $!";

my (@carprice, @array);
while(<FH>){
 @array = split/,/;
 push @carprice, $array[1] if $array[0] =~ /Car/;
 }

# put in your row and columns size
 my ($x, $y) = ($#carprice-1, 10);
#my($x,$y) = (int(($#carprice-1)/2), int(($#carprice-1)/2));

#my $winner = int rand($x * $y);
my $winner = int rand($#carprice);
#print "$winner\n";

my $mw = MainWindow->new;
my $vh = $mw->vrootheight-50;# -100; #get window full size
my $vw = $mw->vrootwidth-50;#  -100;  #with some margin maybe

#my $xsize = $vw/$x; #cell sizes
#my $ysize = $vh/$y;
my $xsize = int $vw/10;
my $ysize = int $vh/10;

$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 => 'small',
              -fill => 'black',
              -text => $carprice[$count],
               -tags => ['rect']
              );

        }
}

$c->CanvasBind("<Button-1>", sub{
            $c->raise( 'winner' ,'rect' );
         });
MainLoop;



sample julypromo.csv is as below.

Car,36208546,10045.22
Car,30205202,10044.66
Car,22001941,10044.35
Car,36227428,10044.23
Car,30202936,10043.22
Car,36220406,10037.33
Car,36220550,10036.13
Car,30204051,10031.82
Car,34205289,10030.83
Car,22002763,10030.33
Car,22014535,10030.02
Car,35207121,10028.54
Car,34212755,10019.36
Car,36226310,10018.79
Car,34212759,10017.41
Car,22002199,10017.08
Car,36205871,10014.77
Car,36226670,10010.63
Car,34210543,10003.52
Car,30205152,10002.31
NULL,30205160,10000.92
okada,22014990,9998.9
okada,36220928,9997.27
okada,22007038,9996.68
okada,22004929,9996.16
okada,30204499,9993.23
okada,35207903,9989.67
okada,36200660,9987.58
okada,22006956,9986.95
okada,35205697,9984.4
okada,34204276,9984.23
okada,22002776,9983.65
okada,36220855,9983.52
okada,34200876,9983.31
okada,22002705,9982.86
okada,22000627,9981.17
okada,36227240,9974.79
okada,35208935,9971.83
okada,22023452,9971.71
okada,22011752,9970.14
okada,34216086,9969.98
okada,35200236,9968.81
okada,36203887,9965.04
okada,30204537,9962
okada,22004378,9961.29
okada,22001621,9960.09
okada,22011738,9958.77
okada,22002604,9953.26
okada,35208344,9948.99
okada,22011842,9948
okada,36205986,9946.83
okada,35204115,9946.58
okada,36202148,9946.57
okada,30202756,9946.55
okada,35207617,9946.14
okada,36220539,9945.91
okada,22023177,9945.11
okada,22017496,9944.68
okada,22011755,9944.41
okada,22008820,9943
okada,22023319,9939.88
okada,22018296,9933.9
okada,36206233,9933.23
okada,36200624,9931.46
okada,22024987,9929.34
okada,36200664,9927.84
okada,36208239,9926.56
okada,36226734,9925.07
okada,22002040,9921.46
okada,34212854,9921.26
okada,35214612,9918.62
okada,22002860,9917.3
okada,35214159,9915.56
okada,22006488,9915.47
okada,22015783,9911.86
okada,22017782,9909.45
okada,22006489,9908.41
okada,36220341,9905.92
okada,30202852,9903.7
okada,22003090,9903.38
okada,22023465,9900.37
okada,22002657,9899.85
okada,36206124,9898.63

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to