use warnings;
use strict;
use Tk;

# Das mw erzeugen
my $mw = MainWindow->new();
$mw->Label(-text => '     Test für Bind     ')->pack();

my $message;

$mw->Label(-textvariable => \$message)
   ->pack(-side => 'bottom', -fill => 'x');

my $b1 = $mw->Button(-text => 'Exit', 
                     -width => 10,
                     -command => sub {exit; })
        ->pack(-side => 'left');
&bind_message($b1, 'Zum Beenden drücken');

my $b2 = $mw->Button(-text => 'Tu nix',
                     -width => 10)
        ->pack(-side => 'left');
&bind_message($b2, 'Button macht gar nichts');

my $b3 = $mw->Button(-text => 'Gib Laut', 
                     -width => 10,
                     -command => [$mw => 'bell'])
        ->pack(-side => 'left');
&bind_message($b3, 'Button macht Lärm');

sub bind_message 
  {
  my ($widget, $msg) = @_;
  $widget->bind('<Enter>', [ sub { $message = $_[1]; }, $msg ]);
  $widget->bind('<Leave>', sub { $message = ''; });
  }

MainLoop;
