Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Problems with Tk::SplashScreen and Tk::Splash

by zentara (Archbishop)
on Jun 16, 2005 at 11:04 UTC ( [id://467243]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Problems with Tk::SplashScreen and Tk::Splash
in thread Problems with Tk::SplashScreen and Tk::Splash

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

Replies are listed 'Best First'.
Re^4: Problems with Tk::SplashScreen and Tk::Splash
by JediWizard (Deacon) on Jun 16, 2005 at 13:05 UTC

    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

      Sorry, I realize you may have used sleep for a quick demo, but I just have to "pick this bone" whenever I see sleep used in GUI code, so that newbies won't think that it is okay to throw sleep into the Tk or gtk2 scripts. The only place sleep should ever be seen in a Tk app is in a thread or after a fork-and-exec. You did notice that your code ran fine without the sleep statements? So it wasn't a problem with the splash screen, it was a problem with sleep in your example. And probably a design problem, where you are trying to use the splash screen as a "please-wait-loading" indicator for your data.

      Sleep in a GUI actually STOPS the GUI event loop from working at all, and using it to demonstrate that some GUI function isn't working, is never the right thing to do. Its like pulling the plug, to demonstrate that the toaster isn't working.

      Sleep stops the "execution pointer" from moving, and in a GUI it must be kept moving. Otherwise the splash will not be destroyed at the desired time, because it's counter was'nt running due to the sleep command.

      Now in your particular case, the sleep demonstrated the problem, but for all the wrong reasons, which is totally misleading. Once again sorry, if I tried to beat you over the head with this. :-)


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://467243]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-20 04:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found