Don't reference removed files in Makefile
[python/dscho.git] / Demo / tkinter / matt / pong-demo-1.py
blob7d405c1654534e0902f7dd2746a72aa9a5a30a45
1 from Tkinter import *
3 import string
6 class Pong(Frame):
7 def createWidgets(self):
8 self.QUIT = Button(self, {'text': 'QUIT',
9 'fg': 'red',
10 'command': self.quit})
11 self.QUIT.pack({'side': 'left', 'fill': 'both'})
13 ## The playing field
14 self.draw = Canvas(self, {"width" : "5i", "height" : "5i"})
16 ## The speed control for the ball
17 self.speed = Scale(self, {"orient": "horiz",
18 "label" : "ball speed",
19 "from" : -100,
20 "to" : 100})
22 self.speed.pack({'side': 'bottom', "fill" : "x"})
24 # The ball
25 self.ball = self.draw.create_oval("0i", "0i", "0.10i", "0.10i", {"fill" : "red"})
26 self.x = 0.05
27 self.y = 0.05
28 self.velocity_x = 0.3
29 self.velocity_y = 0.5
31 self.draw.pack({'side': 'left'})
34 def moveBall(self, *args):
35 if (self.x > 5.0) or (self.x < 0.0):
36 self.velocity_x = -1.0 * self.velocity_x
37 if (self.y > 5.0) or (self.y < 0.0):
38 self.velocity_y = -1.0 * self.velocity_y
40 deltax = (self.velocity_x * self.speed.get() / 100.0)
41 deltay = (self.velocity_y * self.speed.get() / 100.0)
42 self.x = self.x + deltax
43 self.y = self.y + deltay
45 self.draw.move(self.ball, `deltax` + "i", `deltay` + "i")
46 self.after(10, self.moveBall)
50 def __init__(self, master=None):
51 Frame.__init__(self, master)
52 Pack.config(self)
53 self.createWidgets()
54 self.after(10, self.moveBall)
57 game = Pong()
59 game.mainloop()