use strict; use warnings; use Tk; my $mw = MainWindow-> new (-height => 200, -width => 300); my @buttons; foreach my $index (1..5){ $buttons[$index] = $mw->Button ( -text => "Ein Button, der selektiert werden kann!", -relief => 'flat', -activebackground => 'lightblue', -cursor => 'hand2', -command => sub {button_aendern_on ($index);}, -borderwidth => '4' )-> pack; } MainLoop (); sub button_aendern_on{ my $number = shift; $buttons[$number]-> configure ( -relief => 'groove', -bg => 'lightyellow', -command => sub {button_aendern_out ($number);} ); print "Button $number wurde selektiert!\n"; } sub button_aendern_out{ my $number = shift; $buttons[$number]-> configure ( -relief => 'flat', -bg => 'SystemButtonFace', -command => sub {button_aendern_on ($number);}, ); print "Button $number wurde deselektiert!\n"; }