in reply to Tk question...

Use $button->DESTROY to get rid of it.

The call to $mw->Button() returns a Button reference. You need that for the DESTROY call.

use Tk; $mw = MainWindow->new; for($i=0;$i<10;++$i) { my $b = $mw->Button( -relief => 'flat', -background =>"#FFFFFF", -width => 2, -height => 2, -text => "B $i", )->pack; $b->configure(-command => [ $b, 'DESTROY' ]); } MainLoop; __END__

The above code destroys a button when you click on it.