7 def createWidgets(self
):
8 self
.QUIT
= Button(self
, {'text': 'QUIT',
10 'command': self
.quit
})
11 self
.QUIT
.pack({'side': 'left', 'fill': 'both'})
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",
22 self
.speed
.pack({'side': 'bottom', "fill" : "x"})
25 self
.ball
= self
.draw
.create_oval("0i", "0i", "0.10i", "0.10i", {"fill" : "red"})
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
)
54 self
.after(10, self
.moveBall
)