in reply to Re^4: Tk - Focus & Mouse - On & Off
in thread Tk - Focus & Mouse - On & Off

Ok, now I see better what you are trying to accomplish... Seems to me like it would be easier to just use the validateCommand and invalidCommand options in the Entries.

See below: Of course the parameters of what constitutes a "bad" entry probably need to be adjusted.

Minor edit: regularized some variables.

#!/usr/bin/perl -w use strict; use Tk; use Tk::Dialog; my %w; # widget hash my @entries = ( { max => 100, min => 10, value => 50 }, { max => 150, min => 15, value => 75 }, { max => 200, min => 20, value => 110 }, ); $w{mw} = MainWindow->new; $w{frame} = $w{mw}->Frame->pack( -padx => 50, -pady => 50 ); for my $i ( 0 .. 2 ) { ${w}{entries}[$i]{name} = $w{frame}->Entry( -relief => 'raised', -textvariable => \$entries[$i]{value}, -validate => 'focusout', -vcmd => sub { $_[0] !~ /\D/ && $_[0] <= $entries[$i]{max} && $_[0] >= $entries[$i]{min}; }, -invcmd => sub { $w{invalid}->configure( -text => ( $_[0] =~ /\D/ ) ? 'Not an integ +er' : ( $_[0] > $entries[$i]{max} ) ? 'Number too l +arge' : ( $_[0] < $entries[$i]{min} ) ? 'Number too s +mall' : 'Bogus entry' ); $w{invalid}->Show; ${w}{entries}[$i]{name}->focus; }, )->pack( -side => 'left', -padx => 50, -pady => 50 ); } $w{invalid} = $w{mw}->Dialog( -title => 'Invalid entry' ); MainLoop;