in reply to a Tk object who knows who he is ?
#!/usr/bin/perl -w use strict; use warnings; use Tk; my %b; #hash to hold button names my @button_names = qw( blue red green white purple orange ); my $mw = new MainWindow(-title => 'Another Button example'); my $fr = $mw->Frame()->pack(-fill => 'x'); foreach my $name (@button_names) { $b{$name} = $fr->Button(-text => $name, -bg => $name, -command => sub{ print "You clicked on $b{$name} which is ", $b{$name}->cget(-bg),"\n " }, )->pack(-side => 'left'); } $mw->after(5000, sub{ foreach my $button (keys %b){ if($button eq 'red'){next} $b{$button}->configure(-bg => 'grey'); } }); MainLoop;
|
|---|