in reply to Perl/Tk widget removal problem...

I was just poking around in the Tk source (I think I'll be able to grok Lex Rex before I understand the Tk source) and it looks like there's no support for gridRemove in the code where I'd expect to find it. Maybe it was removed, or never added in the first place?

In Tk/ (I THINK this is part of the dispatch mechanism):

sub grid { local $SIG{'__DIE__'} = \&Carp::croak; my $w = shift; if (@_ && $_[0] =~ /^(?:bbox|columnconfigure|configure|forget|info|lo +cation|propagate|rowconfigure|size|slaves)$/x) { my $opt = shift; Tk::grid($opt,$w,@_); } else { # Two things going on here: # 1. Add configure on the front so that we can drop leading '-' Tk::grid('configure',$w,@_); # 2. Return the widget rather than nothing return $w; } }

Note that a direct call to &Tk::grid with the 'remove' argument works:

$ perl -MTk -e '$m=tkinit; $f=$m->Frame->pack; $b=$f->Button(-text=>"F +oo")->grid; $m->after(750,sub{Tk::grid("remove",$b)}); MainLoop'

This patch to Tk/ version 3.080 (Tk 800.024) seems to fix the problem for me:

--- 2003-08-29 14:53:46.000000000 -0500 +++ 2003-08-29 14:45:14.000000000 -0500 @@ -61,7 +61,7 @@ use Tk::Submethods( 'grab' => [qw(current status release -global)], 'focus' => [qw(-force -lastfor)], 'pack' => [qw(configure forget info propagate sl +aves)], - 'grid' => [qw(bbox columnconfigure configure for +get info location propagate rowconfigure size slaves)], + 'grid' => [qw(bbox columnconfigure configure for +get info location propagate remove rowconfigure size slaves)], 'form' => [qw(check configure forget grid info s +laves)], 'event' => [qw(add delete generate info)], 'place' => [qw(configure forget info slaves)], @@ -1060,7 +1060,7 @@ { local $SIG{'__DIE__'} = \&Carp::croak; my $w = shift; - if (@_ && $_[0] =~ /^(?:bbox|columnconfigure|configure|forget|info|l +ocation|propagate|rowconfigure|size|slaves)$/x) + if (@_ && $_[0] =~ /^(?:bbox|columnconfigure|configure|forget|info|l +ocation|propagate|remove|rowconfigure|size|slaves)$/x) { my $opt = shift; Tk::grid($opt,$w,@_);


Replies are listed 'Best First'.
Re^2: Perl/Tk widget removal problem...
by ig (Vicar) on Feb 19, 2011 at 05:44 UTC

    More than 10 years later (Tk/ version 4.035) and the bug (inconsistency between documentation and implementation) still exists. Fortunately, your patch still works, except for the line numbers.

    I have tested minimally and have no idea why this method is not supported. Maybe they have left it out for good reason that I am, thus far, blissfully unaware of.