in reply to Problems with Tk::SplashScreen and Tk::Splash

Check out Petruchio's scratchpad He's got an example that worked for me.

I think the small window that you see is actually your SplashScreen. You may just need to tweak it a bit (i.e. make it bigger) to get it to do what you want.

Also I believe the $image that Tk::Splash is looking for is a TK::Photo object
  • Comment on Re: Problems with Tk::SplashScreen and Tk::Splash

Replies are listed 'Best First'.
Re^2: Problems with Tk::SplashScreen and Tk::Splash
by JediWizard (Deacon) on Jun 15, 2005 at 18:26 UTC

    Thank you for your help. Unfortunately this does not quite achieve what I want. For some (slightly frustrating) reason, execution of the program is halted while the splash screen is displayed (the screen does not appear until the call to destroy, which is a blocking call (see below)). I want the splash screen to display while initialization continues in the background.
    Yarr!

    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Splashscreen; my $mw = MainWindow->new; $mw->Button( -text => 'Exit', -command => sub {exit} )->pack; my $sp = $mw->Splashscreen; $sp->Label(-text => 'Tk... Ick!', -font => [-size => 250])->pack; $sp->Splash; #nothing displayed yet sleep(10); # Still no splash screen $sp->Destroy(5000); # Now we see the splash screen # But execution of the program is on hold until # the screen goes away... Boo! MainLoop;

    They say that time changes things, but you actually have to change them yourself.

    —Andy Warhol

      You need to specify the time in the ->Splash call and do an update before you start your initialization. That way the splash screen will be forced to display before it starts.

      here's another example. Uncomment the ->withdraw line to hide the main window during the splash.

      #!/usr/local/bin/perl -w use strict; use vars qw($mw $sp); use Tk; BEGIN{ require Tk::Splashscreen; use Tk; $mw = MainWindow->new(-title=>'text'); $sp = $mw->Splashscreen(); $sp->Label( -text => 'Starting up', -width => 20, -height => 10, -font => [-size => 50] )->pack(); $sp->Splash(5000); # init splash screen $sp->update; # and display it #$mw->withdraw; # hide main widow during init for my $x(0..20) # junk { for my $y (0..20) { $mw->Label( -text => "$x:$y", )->grid( -row => $x, -column => $y ); } } sleep 3; # and a little wait if desired $sp->Destroy(); # get rid of Splash $mw->deiconify; # and show main window } MainLoop;

        You got it. Thank you much. thundergnat++


        They say that time changes things, but you actually have to change them yourself.

        —Andy Warhol

      NEVER use "sleep" in a GUI event loop, or you will block your gui from functioning the way you expect. Tk has a non-blocking sleep :
      #instead of sleep(10); #use $mw->after(10);
      and your code example will run.

      In GUI programing always think in terms of the "event loop". The event loop dosn't start to run until you get to the MainLoop line. But if you sleep(10), it takes 10 seconds to start.


      I'm not really a human, but I play one on earth. flash japh

        I used sleep simply to illustrate a point in my example. My real application does several select statemnets froma database, and populates widgets based on them, during initialization. This takes time, hence the need for a splash screen.


        They say that time changes things, but you actually have to change them yourself.

        —Andy Warhol