redss has asked for the wisdom of the Perl Monks concerning the following question:
I want a Tk program to perform a subroutine that takes a few seconds when a button is pushed. But I don't want to wait on the the subroutine before returning control to the mainloop. When the subroutine finishes I want it to update the title on the button.
So in the below example, when the button is clicked, I want the button label to immediately update to "step two", then whenever the function finishes, to update to step 3, rather than tie up control while waiting for the function to finish.
How can I do this?
use Tk; + + $main = MainWindow->new(); + + $button = $main->Button(-text => "step one", -command => \&fun); + $button->pack(); + + MainLoop(); + + sub fun { $button->configure(-text => "step two" ); sleep 1; $button->configure(-text => "step three" ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to fork & join in tk?
by kcott (Archbishop) on Apr 23, 2017 at 05:46 UTC | |
|
Re: how to fork & join in tk?
by tybalt89 (Monsignor) on Apr 23, 2017 at 16:31 UTC | |
|
Re: how to fork & join in tk?
by zentara (Cardinal) on Apr 23, 2017 at 15:07 UTC | |
by marioroy (Prior) on Apr 23, 2017 at 19:28 UTC | |
by zentara (Cardinal) on Apr 24, 2017 at 16:03 UTC | |
by marioroy (Prior) on Apr 24, 2017 at 18:42 UTC | |
|
Re: how to fork & join in tk?
by marioroy (Prior) on Apr 23, 2017 at 02:32 UTC | |
by marioroy (Prior) on Apr 23, 2017 at 07:51 UTC |