from Tkinter import *
import random

class MovingBallApp():
    def __init__(self, master):
        self.w = Canvas(master, width=200, height=200)
        self.w.grid(column=0,row=0)
        self.x = 5
        self.y = random.randint(0,200)
        self.dx = 2
        self.dy = random.randint(-5,5)
        self.ball = self.w.create_oval(self.x, self.y, self.x+20, self.y+20,
                                       fill="blue")
        self.w.after(100, self.move)

    def move(self):
        self.x += self.dx
        self.y += self.dy
        self.w.coords(self.ball, self.x, self.y, self.x+20, self.y+20)
        self.w.after(100, self.move)
        

root = Tk()
app = MovingBallApp(root)
root.mainloop()
