Others have given good answers to your question, but neglected to chastise you for your lousy code. So just in case this is homework, I offer these comments.:-)
First off, if you added
use warnings;
use strict;
you would have received a fatal error that there is no Tk::CheckButton module. Fix that error, then you load Tk::LabFrame but never use it. Instead you use Tk::Pane to make a scrolled frame, which has its packing options unset, so the whole checkbutton list is crushed to 1 entry. You even use the .. operator incorrectly, but luckily it seems to work.
foreach $i (1...20) # that ... should be ..
Your @a array only has 10 elements one to ten, but you make 20 checkbuttons.
If you are a student, I wouldn't even accept this as a valid submission.
Here is some unflawed code for you to look at.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::Pane;
my @a=qw/one two three four five six seven eight nine ten/;
my $mw = MainWindow->new;
$mw->geometry('200x200');
my $f = $mw->Scrolled("Frame",-borderwidth => 3, -relief => 'groove',-
+height=>20)
->pack(-expand=> 1, -fill=>'both');
foreach my $i (0 .. 19){ # this should be foreach my $i (@a), but it'
+s your code :-)
print "$i\n";
my $c = $f->Checkbutton(-text=>$a[$i],-command=>[ \&fun, $a[$i] ] )->p
+ack();
$i++;
}
MainLoop;
sub fun{
print "@_\n";
}
|