Splash screens are those windows that pop up for the amusement of the user while a long-loading program gets underway. Some folks display their splash screens during program initialization sequentially, so that if a splash screen stays on the display for three seconds, the program takes three seconds longer to load. We, however, prefer that our splash screens run in parallel with program initialization. One approach might be:
Create a Toplevel splash screen.
Queue a timer event to set a variable after X seconds.
Wait for splash timer to expire with
Destroy splash screen and enter
There’s a problem with this scheme: if initialization takes too
long and the splash timer expires, the
waitVariable will hang. This can also happen if
the splash delay is set too small. We could use
waitVariableX with a timeout, resulting in code
that might look like this:
my $mw = MainWindow->new; $mw->withdraw; my ($splash_scr, $splash_tid, $splash_var) = splash 3000; # - program initialization. my $why = $mw->&waitVariableX(3000, $splash_var); $splash_scr->afterCancel($splash_tid); $splash_scr->destroy; $mw->deiconify;
But this just doesn’t feel right. First, having the splash screen remain on the screen for X seconds one time, and X+3 seconds at others, is an unsatisfactory hack. Second, too much of the work is left to the application. We need to encapsulate things in a mega-widget. Besides, there are some subtle details, as we are about to see. ...