Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- from threading import *
- window = Tk()
- canvas = Canvas(window, width = 400, height = 300)
- canvas.pack()
- x0 = 10
- y0 = 50
- x1 = 60
- y1 = 100
- i = 0
- deltax = 2
- deltay = 3
- which = canvas.create_oval(x0,y0,x1,y1,
- fill="red",
- tag='redBall')
- from time import sleep
- def otherthread():
- while 1:
- global x1, x0, y1, y0, deltax, deltay
- if x1 >= 400:
- deltax = -2
- if x0 < 0:
- deltax = 2
- if y1 > 300:
- deltay = -3
- if y0 < 0:
- deltay = 3
- x0 += deltax
- x1 += deltax
- y0 += deltay
- y1 += deltay
- sleep(0.02)
- t = Thread(None, otherthread)
- t.start()
- while True:
- canvas.move('redBall', deltax, deltay)
- canvas.after(20)
- canvas.update()
- window.mainloop()
Add Comment
Please, Sign In to add comment