| 1 |
from Tkinter import * |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class Test(Frame): |
| 10 |
def printit(self): |
| 11 |
print "hi" |
| 12 |
|
| 13 |
def createWidgets(self): |
| 14 |
self.QUIT = Button(self, text='QUIT', foreground='red', |
| 15 |
command=self.quit) |
| 16 |
self.QUIT.pack(side=BOTTOM, fill=BOTH) |
| 17 |
|
| 18 |
self.draw = Canvas(self, width="5i", height="5i") |
| 19 |
|
| 20 |
self.speed = Scale(self, orient=HORIZONTAL, from_=-100, to=100) |
| 21 |
|
| 22 |
self.speed.pack(side=BOTTOM, fill=X) |
| 23 |
|
| 24 |
|
| 25 |
self.draw.create_rectangle(0, 0, 10, 10, tags="thing", fill="blue") |
| 26 |
self.draw.pack(side=LEFT) |
| 27 |
|
| 28 |
def moveThing(self, *args): |
| 29 |
velocity = self.speed.get() |
| 30 |
str = float(velocity) / 1000.0 |
| 31 |
str = "%ri" % (str,) |
| 32 |
self.draw.move("thing", str, str) |
| 33 |
self.after(10, self.moveThing) |
| 34 |
|
| 35 |
def __init__(self, master=None): |
| 36 |
Frame.__init__(self, master) |
| 37 |
Pack.config(self) |
| 38 |
self.createWidgets() |
| 39 |
self.after(10, self.moveThing) |
| 40 |
|
| 41 |
|
| 42 |
test = Test() |
| 43 |
|
| 44 |
test.mainloop() |