Tk mainloop()

Antti Kaihola akaihola at ambi-spam-me-not-tone.com
Sun Jul 20 13:48:22 EDT 2003


> Hi, I have a question: how do you execute an arbitrary function in Tk fooBar.mainloop()?
> I need to change the contents of a label every second, but I think I will also use some other functions as well...

from Tkinter import *

class MyApp(Tk):

     def __init__(self):
         Tk.__init__(self, className='MyApp')
         self.after(1000, self.label_timeout)
         # add whatever initialization you may need

     def label_timeout(self):
         # change label contents here
         self.after(1000, self.timeout)

myapp = MyApp()
myapp.protocol('WM_DELETE_WINDOW', on_close)
myapp.mainloop()





More information about the Python-list mailing list