1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!perl use strict; use warnings; use Tk; my $mw = Tk::MainWindow->new(); my $entry = $mw->Entry()->pack(); my $var = '123'; $entry->bind('<KeyPress>', sub{ print "$var\n"; }); $mw->MainLoop();
1 2 3 4 5 6 7 8 9 10 11 12 13 14
use strict; use warnings; use Tk; my $mw = Tk::MainWindow->new(); my $entry = $mw->Entry()->pack(); my $var = '123'; # sub in []-klammern packen $entry->bind('<KeyPress>', [sub{ $entry->configure(-text => "$_[1]\n"); }, $var]); $mw->MainLoop();