use Tk; use utf8; use strict; use warnings; my($Test, $Laenge, $Meldung) = ""; my $mw = MainWindow->new(); my $ent = $mw->Entry( -textvariable => \$Test, -validate => 'key', -validatecommand => \&check, )->pack(-side=>'top'); MainLoop(); sub check { my $color = 'black'; my $returncode = 1; if ( 1 < length $Test ) { $color = 'red'; } $ent->configure( -foreground => $color ); return $returncode; }