(Tkinter) Adding delay to PopUpMsg

Eric Brunel eric_brunel at despammed.com
Fri Mar 18 10:10:12 CET 2005

On 17 Mar 2005 23:40:20 -0800, Harlin Seritt <harlinseritt at yahoo.com> wrote:
> I am working on making something called a PopMsg widget which is
> actually identical to a Balloon widget from Pmw. Here is the code:
> ---code---
> from Tkinter import *
> import time
> class PopMsg:
> 	def showmsg(self, event):
> 		for a in range(10000000): pass

Very effective way to waste a lot of CPU time and to make your delay totally dependent on the CPU speed! Why don't you at least use time.sleep (that you use some lines below for no apparent reason BTW)?

[snip code]
> My problem you'll notice is that I tried to put something of a 'delay'
> that will allow the popup to show a few seconds after the cursor has
> entered the targeted widget's space (in this case the button). That
> works ok but I've found that while waiting I can't activate (or
> 'click') on the button until the PopMsg has shown up. Is there anything
> I can do to solve this problem?

Use Tkinter widgets' "after" method; the binding on <Enter> on the widget should do something like:

self.widget.after(1000, self.showmsg)

This tells the tk main loop to wait 1000 milliseconds, then run the method. Note that no event will be passed, so you should make the "event" parameter in showmsg optional. This is an active wait, so all other events will be treated. If for some reason, you want to cancel the action, you can remember the result of the "after" method, and then pass it to the after_cancel method on the same widget:

x = self.widget.after(1000, self.showmsg)

python -c 'print "".join([chr(154 - ord(c)) for c in "U(17zX(%,5.z^5(17l8(%,5.Z*(93-965$l7+-"])'

More information about the Python-list mailing list