Generating an event in Tkinter

nharlow at my-deja.com nharlow at my-deja.com
Thu Sep 2 14:02:25 EDT 1999


Thank you so much for all your help.  It was the widget.update() that
did it for me.  Thanks.  I look forward to seeing your Tkinter book
from O'Reilly.

Nick Harlow


In article <014801bef523$808828a0$f29b12c2 at secret.pythonware.com>,
  "Fredrik Lundh" <fredrik at pythonware.com> wrote:
> <nharlow at my-deja.com> wrote:
> > import time
> > name="Analyze"
> > while i< 100:
> > print "%s: This is %s time through the loop"%(name,i+1)
> > widget.event_generate("<<foo>>")
> > widget.bind("<<foo>>", lambda e, y=1, x=time.sleep: x(y))
> > i=i+1
>
> > It just locks up; I don't even get any errors.
>
> no errors at all?  not even some-
> thing like:
>
> Traceback (innermost last):
>   File "example.py", line 3, in ?
>     while i< 100:
> NameError: i
>
> ???
>
> if I set "i" to 0, and create a widget,
> your program works just fine.  or in
> other words, the loop will now send
> 100 events to the widget, which,
> whenever it gets around to check
> the event queue, will block for
> one second per event.
>
> the following version increases the
> chance that the widget actually gets
> around to process your event:
>
> from Tkinter import *
> import time
>
> widget = Tk()
> widget.bind("<<foo>>", lambda e, y=1, x=time.sleep: x(y))
>
> name="Analyze"
>
> for i in range(100):
>         print "%s: This is %s time through the loop"%(name,i+1)
>         widget.event_generate("<<foo>>")
>         widget.update() # process events
>
> mainloop()
>
> btw, I think you might be better off using a
> timer [1], but that's me...
>
> </F>
>
> 1) http://www.pythonware.com/library/tkinter/introduction/basic-
widget-methods.htm
> => alarm handlers and other non-event callbacks
>
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list