#Simulate a bouncing ball import tkinter as tk import time root = tk.Tk() Frame_Width = 800 Frame_Height = 600 g = print("%dx%d",(Frame_Width, Frame_Height)) root.geometry(g) canvas = tk.Canvas(root) canvas. pack() canvas.config(width = Frame_Width, height = Frame_Height) root.title("Boing") SIZE = 50 x1 = Frame_Width / 2 y1 = Frame_Height / 4 velx = 2 vely = 2 while True: canvas.delete("all") canvas['bg'] = "gray" x1 = x1 + velx y1 = y1 + vely x2 = x1 + SIZE y2 = y1 + SIZE if (y2 > Frame_Height): vely = -vely if (x2 > Frame_Width): velx = -velx if (x1 < 0): velx = -velx #Create Lines for y in range(0,Frame_Height,40): canvas.create_rectangle([0,y,Frame_Width,y+1],fill="Magenta",width=0) for x in range(0,Frame_Width,40): canvas.create_rectangle([x,0,x+1,Frame_Height],fill="Magenta",width=0) #Create Circle canvas.create_oval([x1,y1,x2,y2],fill="Red",width=0) #width is an optional argument vely += 0.2 #0.2 is our acceleration in the y direction canvas.update() time.sleep(0.01) root.destroy()