| 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.
|