For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > January 2005 > how to refresh a pane









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 how to refresh a pane
jiehuang001@hotmail.com

2005-01-24, 8:57 pm

I used some code like the following to create a Pane with some
Checkbuttons. The array @List_of_Names is generated dynamically from a
database query.

How to create a "Refresh" button so that I don't need to stop and then
start the
program again in order to reflect the change of the array?

Thanks very much.

Jie Huang


====part of the code==
@List_of_Names =??? # generated from a query
$pane_body = $mw -> Scrolled (Pane, -scrollbars => 'e') -> pack();
foreach (@List_of_Names) {
$the_pane -> Checkbutton(-text=>$_) ->pack;
}

Marc Dashevsky

2005-01-24, 8:57 pm

In article <1106598579.877398.246410@z14g2000cwz.googlegroups.com>, jiehuang001
@hotmail.com says...
> I used some code like the following to create a Pane with some
> Checkbuttons. The array @List_of_Names is generated dynamically from a
> database query.
>
> How to create a "Refresh" button so that I don't need to stop and then
> start the
> program again in order to reflect the change of the array?
>
> Thanks very much.


use strict;
use Tk;

my $Frame;
my $mw = tkinit;
my $pane = $mw->Scrolled('Pane',
-scrollbars => 'e',
)->pack(-expand => 1, -fill => 'both');
$mw->Button(
-text => 'Refresh',
-command => \&Refresh,
)->pack;
Refresh();
MainLoop;

sub Refresh {
my @a;
for (my $i = 0; $i < 10; $i++) {push(@a, int(rand(100)))}
DisplayCheckButtons($pane, @a)
}

sub DisplayCheckButtons {
my($parent, @names) = @_;
$Frame->destroy if $Frame;
$Frame = $parent->Frame->pack(-expand => 1, -fill => 'both');
map {$Frame->Checkbutton(-text => $_)->pack} @names;
}

--
Go to http://MarcDashevsky.com to send me e-mail.
Sponsored Links







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

Copyright 2008 codecomments.com