| 1 | from Tkinter import *
|
|---|
| 2 |
|
|---|
| 3 | # this is the same as simple-demo-1.py, but uses
|
|---|
| 4 | # subclassing.
|
|---|
| 5 | # note that there is no explicit call to start Tk.
|
|---|
| 6 | # Tkinter is smart enough to start the system if it's not already going.
|
|---|
| 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 | # all of these work..
|
|---|
| 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()
|
|---|