summaryrefslogtreecommitdiff
path: root/Demo/tkinter/matt/pong-demo-1.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1994-10-07 09:55:26 +0000
committerGuido van Rossum <guido@python.org>1994-10-07 09:55:26 +0000
commit35820f77e41a8a41a695e08c041eed5e2e2ff3ef (patch)
tree2bf45f05d7530067911726bf9a3e56b453d49db5 /Demo/tkinter/matt/pong-demo-1.py
parent884657af490e79e8e4a3038b439af9713cb64bc8 (diff)
downloadcpython-git-35820f77e41a8a41a695e08c041eed5e2e2ff3ef.tar.gz
Matt's examples
Diffstat (limited to 'Demo/tkinter/matt/pong-demo-1.py')
-rw-r--r--Demo/tkinter/matt/pong-demo-1.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/Demo/tkinter/matt/pong-demo-1.py b/Demo/tkinter/matt/pong-demo-1.py
new file mode 100644
index 0000000000..7d405c1654
--- /dev/null
+++ b/Demo/tkinter/matt/pong-demo-1.py
@@ -0,0 +1,59 @@
+from Tkinter import *
+
+import string
+
+
+class Pong(Frame):
+ def createWidgets(self):
+ self.QUIT = Button(self, {'text': 'QUIT',
+ 'fg': 'red',
+ 'command': self.quit})
+ self.QUIT.pack({'side': 'left', 'fill': 'both'})
+
+ ## The playing field
+ self.draw = Canvas(self, {"width" : "5i", "height" : "5i"})
+
+ ## The speed control for the ball
+ self.speed = Scale(self, {"orient": "horiz",
+ "label" : "ball speed",
+ "from" : -100,
+ "to" : 100})
+
+ self.speed.pack({'side': 'bottom', "fill" : "x"})
+
+ # The ball
+ self.ball = self.draw.create_oval("0i", "0i", "0.10i", "0.10i", {"fill" : "red"})
+ self.x = 0.05
+ self.y = 0.05
+ self.velocity_x = 0.3
+ self.velocity_y = 0.5
+
+ self.draw.pack({'side': 'left'})
+
+
+ def moveBall(self, *args):
+ if (self.x > 5.0) or (self.x < 0.0):
+ self.velocity_x = -1.0 * self.velocity_x
+ if (self.y > 5.0) or (self.y < 0.0):
+ self.velocity_y = -1.0 * self.velocity_y
+
+ deltax = (self.velocity_x * self.speed.get() / 100.0)
+ deltay = (self.velocity_y * self.speed.get() / 100.0)
+ self.x = self.x + deltax
+ self.y = self.y + deltay
+
+ self.draw.move(self.ball, `deltax` + "i", `deltay` + "i")
+ self.after(10, self.moveBall)
+
+
+
+ def __init__(self, master=None):
+ Frame.__init__(self, master)
+ Pack.config(self)
+ self.createWidgets()
+ self.after(10, self.moveBall)
+
+
+game = Pong()
+
+game.mainloop()