Gossamer Forum
Home : General : Perl Programming :

how to change a HList column value randomly

Quote Reply
how to change a HList column value randomly
Hi
I have HList tree with three columns and ten rows.
After launching the gui, I want to change the value of one column
randomly (after every 2,3 or 5 secs). Maximum interval would be 5 but not more than that.

Following is my code, please help me with the last part .
The gui should get launched first. And then every 2,3 or 5 sec the value should start getting changed.
Never mind the values of the cells.
[/size]

Code:
use strict;

use warnings;

use Tk;


use Tk::HList;


use Tk::ItemStyle;



my $mw = MainWindow->new();

my $hlistframe = $mw->Frame()->pack(-fill=> 'both', -expand => 1);

my $font = "{helvetica} -12 bold";

my $hl = $hlistframe->Scrolled('HList',

-scrollbars => 'ose', -columns =>7 , -header => 1, -width => 50, -command => sub {print "AAA\n";}, )->pack(-fill => 'both',-expand =>1 ); my $name = $hl->Label(-text => "Name", -anchor => 'w',-font => $font);

$hl->headerCreate(0,-itemtype => 'window',-widget => $name);


my $DOB = $hl->Label(-text => "DOB", -anchor => 'w',-font => $font);

$hl->headerCreate(1,-itemtype => 'window',-widget => $DOB);

my $Address = $hl->Label(-text => "Address", -anchor => 'w',-font => $font);

$hl->headerCreate(2,-itemtype => 'window',-widget => $Address);

my $style1 = $hl->ItemStyle('text', -selectforeground =>'black', -anchor =>'nw',-background =>'green',-font => $font);

my $style2 = $hl->ItemStyle('text', -selectforeground =>'black', -anchor =>'nw',-background =>'red',-font => $font);

&populate();

sub populate

{

my $path = 0;

foreach my $entry (1 .. 10)

{

insertData($path,$entry);

$path++;

}

}

sub insertData

{

my ($path,$entry) = @_;

$hl->add($path);



$hl->itemCreate($path,0,-text => "thomas");

$hl->itemCreate($path,1,-text => "20-10-2000");

$hl->itemCreate($path,2,-text => "102 street" , -style => $style1);

}

=cut

# please help me with how to change value of two cells randomly

while(rand)

{ $hl->itemConfigure( 2, 2, -text => "202 street", -style => $style2 );

$hl->itemConfigure( 3, 2, -text => "202 street", -style => $style2 );

}

=cut

MainLoop;[/code][/size]