Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Looping a widget in Perl/Tk

31 views
Skip to first unread message

ket

unread,
Oct 5, 2009, 8:25:54 PM10/5/09
to
I am trying to display a large no of radiobuttons and removing few
based on selection.
this is the piece of code for it.
When i try to do a packForget or gridForget, i get the following
warning

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;

Marc Dashevsky

unread,
Oct 5, 2009, 10:38:30 PM10/5/09
to
In article <0dd53826-adc6-47f6...@j9g2000prh.googlegroups.com>, kates15
@gmail.com says...

> I am trying to display a large no of radiobuttons and removing few
> based on selection.
> this is the piece of code for it.
> When i try to do a packForget or gridForget, i get the following
> warning
>
> Tk::Error: Can't call method "packForget" on an undefined value at
> filename.pl line xx.


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.

ket

unread,
Oct 6, 2009, 5:14:50 PM10/6/09
to
On Oct 5, 7:38 pm, Marc Dashevsky <use...@MarcDashevsky.com> wrote:
> In article <0dd53826-adc6-47f6-8ab4-d728c121e...@j9g2000prh.googlegroups.com>, kates15

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

Marc Dashevsky

unread,
Oct 6, 2009, 9:00:07 PM10/6/09
to
In article <b1fd779a-e19c-47b3...@d9g2000prh.googlegroups.com>, kates15
@gmail.com says...

> Is there some way by which i can do pack forget to all the displayed
> radiobutton along with the one which is selected.

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]);

Marc Dashevsky

unread,
Oct 6, 2009, 9:05:46 PM10/6/09
to
In article <MPG.2535b21bf...@news.supernews.com>, use...@MarcDashevsky.com
says...

> In article <b1fd779a-e19c-47b3...@d9g2000prh.googlegroups.com>, kates15
> @gmail.com says...
> > Is there some way by which i can do pack forget to all the displayed
> > radiobutton along with the one which is selected.
>
> 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.

arguments, not commands

0 new messages