#!/usr/bin/perl use strict; use warnings; use diagnostics; use Tk; my $mw = new MainWindow; foreach my $text (qw/eins zwei drei/) { my $b = $mw->Button(-text => "Button Nr. $text", -command => sub { print "bzzzzzzzzz $text\n" }, ) ->pack(-fill => 'x'); $b->bind('' => [ \&printButtonLabel, $text, "gedrueckt" ] ); $b->bind('' => [ \&printButtonLabel, $text, "losgelassen" ] ); } MainLoop(); sub printButtonLabel ($$$) { my $widget = shift; my $text = shift; my $anhang = shift; my $aufschrift = $widget->cget('-text'); print "Button: $text (Aufschrift '$aufschrift') $anhang\n"; }