in reply to Perl Tk - Change button state based on event

Another way, using 'validate':

use strict; use warnings; use Tk; my $mw = MainWindow->new; my $firstentry = $mw->Entry( -validate => 'focusout', -vcmd => [ \&check_state ], )->pack(); my $secondentry = $mw->Entry( -validate => 'focusout', -vcmd => [ \&check_state ], )->pack(); my $but = $mw->Button( -text => "OK", -state => 'disabled' )->pack(); MainLoop; sub check_state { if ( $firstentry->get and $secondentry->get ) { $but->configure( -state => 'normal' ); } else { $but->configure( -state => 'disabled' ); } }

Replies are listed 'Best First'.
Re^2: Perl Tk - Change button state based on event
by colpwd (Initiate) on Jun 13, 2011 at 22:03 UTC

    Oh! This is great. Thanks a lot for this. I was not too sure how to use validate, but based on the documentation, i had an inkling that it was capable of doing this task. Thanks again!