• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from Tkinter import *
2
3# This program shows how to use the "after" function to make animation.
4
5class Test(Frame):
6    def printit(self):
7        print "hi"
8
9    def createWidgets(self):
10        self.QUIT = Button(self, text='QUIT', foreground='red',
11                           command=self.quit)
12        self.QUIT.pack(side=LEFT, fill=BOTH)
13
14        self.draw = Canvas(self, width="5i", height="5i")
15
16        # all of these work..
17        self.draw.create_rectangle(0, 0, 10, 10, tags="thing", fill="blue")
18        self.draw.pack(side=LEFT)
19
20    def moveThing(self, *args):
21        # move 1/10 of an inch every 1/10 sec (1" per second, smoothly)
22        self.draw.move("thing", "0.01i", "0.01i")
23        self.after(10, self.moveThing)
24
25
26    def __init__(self, master=None):
27        Frame.__init__(self, master)
28        Pack.config(self)
29        self.createWidgets()
30        self.after(10, self.moveThing)
31
32
33test = Test()
34
35test.mainloop()
36