Generating an event in Tkinter

nharlow at my-deja.com nharlow at my-deja.com
Tue Aug 31 18:30:31 EDT 1999


In article <011701bef37e$bcd9ece0$f29b12c2 at secret.pythonware.com>,
  "Fredrik Lundh" <fredrik at pythonware.com> wrote:
> nharlow at my-deja.com wrote:
> > I want to generate a dummy event from within a program.  Then bind a
> > callback to this event.
> >
> > How do I do that?
> >
> > In straight tk, it would be something like:
> >  event generate parent_window <<foo>>
>
> parent_window.event_generate("<<foo>>")
>
> (additional options can be given as
> keyword arguments)

I want to do the following:
iterate over a while loop and output some text to a text widget.
sleep for one second between iterations
here's the code I tried.  It doesn't like the way I am trying to make
it sleep.


i=sleeper=0
from time import sleep
name="analyzer"
while i< 100:
	print "%s: This is %s time through the loop"%(name,i+1)
	widget.event_generate("<<foo>>")
	widget.bind("<<foo>>",lambda x=sleep, y=1:x(y))
	i=i+1

I get the following error:
Traceback (innermost last):
  File "c:\program files\python\lib\lib-tk\Tkinter.py", line 752, in
__call__
    return apply(self.func, args)
  File "C:\nick\GUI\spidergui.py", line 145, in <lambda>
    widget.bind("<<foo>>",lambda x=sleep, y=1:x(y))
AttributeError: no __call__ method defined


what is the best way to do what I am trying to do?

Nick


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