Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Problems with Tk::SplashScreen and Tk::Splash

by JediWizard (Deacon)
on Jun 15, 2005 at 15:03 UTC ( [id://466937]=perlquestion: print w/replies, xml ) Need Help??

JediWizard has asked for the wisdom of the Perl Monks concerning the following question:

Hallo,

I have a tk application I've been working on which takes a significant amount of time to initialize. I would like to have a splash screen to alert the users that things are starting up (I've had some complaints that "It doesn't look like it is doing anything" and "it is frozen" when initializing). A quick search of cpan revealed Tk::Splash, Tk::Splashscreen, and Tk::FastSplash. Which all look like they'd fit the bill. Tk::Splash and Tk::Splash screen were available in the ppm repositories I use, so I started with them. Here is a sample of my code to use Tk::SpalshScreen:

#!/usr/local/bin/perl -w use strict; use vars qw($mw $sp); use Tk; sleep(10); MainLoop; BEGIN{ require Tk::Splashscreen; use Tk; $mw = MainWindow->new(-title=>'text'); $sp = $mw->Splashscreen(); $sp->Label(-text=>'Starting up')->pack(); $sp->Splash(10000); }

When I run this, I see a window come up immediately, but it is blank (i.e. my label is not there) and when the appicaltion is done initializing another window flashes by very quickly (which appears to be may splash screen, but I can't tell as it only apears for less than 1 second). That behavior does not seem usefull in any way, did I do something wrong?

Using Tk::Spalsh, I can't even get things running. According top the docs:

$splash = Tk::Splash->Show($image, $width, $height, $title, $overrideredirect);

Should work... but there is no indication about what exacltly the "$image" argument should be. I've tried passing it a path to a gif, a jpg and a bmp, all of which result in an error. The error displays a string of random binary characters and tells me that they do not apear to be an image. What have I missed? Am a sopposed to be passing some form of image object? Or a filehandle perhaps?

Please guide me with wisdom. All Help/Suggestions appriciated

P.S. I am running Active State Perl 5.6.1 Build 633 on Windows 2000 Professional


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

—Andy Warhol

Replies are listed 'Best First'.
Re: Problems with Tk::SplashScreen and Tk::Splash
by NateTut (Deacon) on Jun 15, 2005 at 16:16 UTC
    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

      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;
        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
Re: Problems with Tk::SplashScreen and Tk::Splash
by Anonymous Monk on Jun 15, 2005 at 18:55 UTC
    You might try something like this for a gif image:
    #!C:/perl/bin/perl.exe use warnings; use Tk; use Tk::ProgressBar::Mac; use Tk::Splashscreen; use subs qw/main/; use strict; main; sub main { my $mw = MainWindow->new; my $splash = $mw->Splashscreen; $splash->Label( -text => 'Presenting your splash screen ...' +, )->pack(qw/-fill both -expand 1/); my $pb = $splash->ProgressBar(-width => 300); $pb->pack(qw/-fill both -expand 1/); $splash->Label( -image => $mw->Photo( -file => Tk->findINC('Some/Path/to/images/splash.gif') ), )->pack; $splash->Splash; my $w = 1; while ($w < 100) { $pb->set($w); $mw->update; $mw->after(1); $w++; } $splash->Destroy; MainLoop; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://466937]
Front-paged by bibliophile
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found