raider2001
Technical User
I'm trying to disable a button using Perl's Tk module. Setting the state to 'disabled' doesn't really disable the button, it just delays the action until after the button is re-enabled. I want to ignore all mouse clicks that occur when the button is disabled. Here's some code to show the problem. If I click when the button is disabled (sleep), the ResetButton subroutine is called after the sleep.
Code:
use Tk;
$Main = MainWindow->new();
$Frame = $Main->Frame();
$Frame->pack();
$Button = $Frame->Button(-text=>'Start', -command=>\&Start);
$Button->pack();
MainLoop();
sub Start() {
$Button->configure(-state => 'disabled');
$Button->update;
sleep(10); # If I click at this time - ResetButton is called later
$Button->configure(-state, 'normal', -command, \&ResetButton, -background, 'green', -activebackground, 'green', -text, 'PASSED', -command => \&ResetButton );
$Button->update;
}
sub ResetButton() {
$Button->configure(-text, 'Start', -activebackground, 'grey', -background, 'grey', -command => \&Start);
$Button->update;
}