use strict; use warnings; use Tk; my $MW = tkinit; my $show_button_text = 'txt'; my $show_button = $MW->Button( -textvariable => \$show_button_text, -command => sub { print "$show_button_text \n"; }, )->pack(qw(-side top -fill x)); my %add_buttons; for my $add_text (qw(a bb xyz)) { $add_buttons{$add_text} = $MW->Button( -text => $add_text, -command => sub { $show_button_text .= " $add_text"; }, )->pack(qw(-side left -expand 1)); } MainLoop;