#!/usr/bin/perl -w use strict; use Tk; my (@entries, @entry_value); # max and min values for Entry boxes my (%maxev, %minev); $maxev{0} = 100; $maxev{1} = 150; $maxev{2} = 200; $minev{0} = 10; $minev{1} = 15; $minev{2} = 20; my $mw = MainWindow->new; my $frame = $mw->Frame()->pack(-padx => 50,-pady => 50); foreach my $i (0..2) { $entry_value[$i] = "$i"; $entries[$i] = $frame->Entry(-relief => 'raised', -textvariable => \$entry_value[$i], )->pack(-side => 'left', -padx => 50,-pady => 50); # $entries[$i]->bind('' => [\&sayHello,$i]); $entries[$i]->bind('' => [\&sayGoodbye,$i]); $entries[$i]->bind('' => [\&sayFocusIn,$i]); $entries[$i]->bind('' => [\&sayFocusOut,$i]); } MainLoop; sub sayHello { my $w = shift; my $id = shift; $w->focus; $frame->grab; print "Hi, I am entry $id!\n"; } sub sayGoodbye { my $w = shift; my $id = shift; $frame->grab; $mw->focus; print "Goodbye, I was entry $id!\n"; } sub sayFocusIn { my $w = shift; my $id = shift; $frame->grab; print "Hi, FocusIn said I am entry $id - value $entry_value[$id]\n"; } sub sayFocusOut { my $w = shift; my $id = shift; my $val_ok; $frame->grab; $val_ok = 'yes'; # check that current valaue is within the min max values if($entry_value[$id] < $minev{$id}) { print "\nEntry $id - value is less than allowed minimum of $minev{$id}\n"; $val_ok = 'no'; } if($entry_value[$id] > $maxev{$id}) { print "\nEntry $id - value is greater than allowed maxmum of $maxev{$id}\n"; $val_ok = 'no'; } if($val_ok eq 'yes') { print "\nEntry $id - value is acceptable\n"; } }