Tk::Error: Can't call method "packForget" on an undefined value at
filename.pl line xx.
for (<@strng>)
{
my @rd = $mw -> Radiobutton (-text => $strng[$i], -variable => $CG, -
value => $strng[$i], -command => sub {next_radio()}) -> pack();
$i = $i + 1;
}
sub next_radio
{
$rd[0] -> packForget();
}
MainLoop;
use strict;
use warnings;
use Tk;
my @s = (qw/a b c d e f g/);
my $variable = 'dummy';
my $mw = tkinit;
my $i = 0;
while ($i < @s) {
my $rd = $mw->Radiobutton(
-text => $s[$i],
-variable => \$variable,
-value => $s[$i],
)->pack();
$rd->configure(-command => [\&next_radio, $rd]);
$i = $i + 1;
}
sub next_radio {
my($w) = @_;
$w->packForget;
}
MainLoop;
> for (<@strng>)
> {
> my @rd = $mw -> Radiobutton (-text => $strng[$i], -variable => $CG, -
> value => $strng[$i], -command => sub {next_radio()}) -> pack();
> $i = $i + 1;
> }
>
> sub next_radio
> {
> $rd[0] -> packForget();
> }
> MainLoop;
>
--
Go to http://MarcDashevsky.com to send me e-mail.
Thanks Marc,
Is there some way by which i can do pack forget to all the displayed
radiobutton along with the one which is selected.
Thank You
Ketan Sharma
The easiest way I can think of is to pack all the radiobuttons
into one frame and then packForget the frame. The example below
is deliberately overwrought because it demonstrates addition
ways to pass commands to callbacks.
use strict;
use warnings;
use Tk;
my @radiobuttons;
my @s = (qw/a b c d e f g/);
my $variable = 'dummy';
my $mw = tkinit;
for (@s) {
push(@radiobuttons,
$mw->Radiobutton(
-text => $_,
-variable => \$variable,
-value => $_,
)->pack()
);
}
for (@radiobuttons) {
$_->configure(-command => [sub { for(@_){$_->packForget} }, @radiobuttons]);
arguments, not commands