Asynchronous event handling...?

Pedro Werneck pedro.werneck at terra.com.br
Mon Jan 24 06:07:43 EST 2005


Hi,

Maybe something like this...



from Tkinter import *
import itertools

class Application(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.grid()
        self.createWidgets()
    def createWidgets(self):
        self.stop = Button(self,text='Emergency Stop!',command=self.stop)
        self.count = Button(self,text='Count',command=self.count)
        self.count.grid(row=0,column=0)
        self.stop. grid(row=0,column=1)

    def count(self):
        self._counter = itertools.count()
        self._id = self.after(0, self._count)

    def _count(self, event=None):
        i = self._counter.next()
        print i
        self.update_idletasks()
        self._id = self.after(0, self._count)

    def stop(self):
        self.after_cancel(self._id)


app = Application()
app.mainloop()


On Mon, 24 Jan 2005 16:52:51 +1100
"Chris Line" <chris321 at hotmail.com> wrote:

> -- 
> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list