Q. How can I get the program to do 'x' after mainloop starts ?

   1 # using the tk timer (Fredrik Lundh, June 1997)
   2 
   3 from Tkinter import *
   4 
   5 root = Tk()
   6 
   7 class App:
   8 
   9     def __init__(self, master):
  10 
  11         self.w = Button(root, text="Waiting", command=self.stop)
  12         self.w.pack()
  13         self.id = self.w.after(1000, self.timer)
  14 
  15     def timer(self):
  16         self.w.config(text=self.w["text"]+".")
  17         self.id = self.w.after(1000, self.timer)
  18 
  19     def stop(self):
  20         self.w.config(bg="gold")
  21         self.w.after_cancel(self.id)
  22 
  23 app = App(root)
  24 
  25 root.mainloop() 
  26 

note the use of after() and after_cancel()

tkinter: UsingTheEventLoop (last edited 2011-04-27 23:39:14 by AnthonyMuss)