Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter
- canvas = tkinter.Canvas(width="640", height="480")
- canvas.pack()
- square = canvas.create_rectangle(250, 250, 300, 300, fill="green")
- direction = 1
- def movement():
- global direction
- x1, y1, x2, y2 = canvas.coords(square)
- print(x1, y1, x2, y2)
- if y1 < 0:
- direction = 1
- if y2 > 480:
- direction = -1
- canvas.move(square, 0, (direction * 3))
- canvas.after(50, movement)
- canvas.bind("<Button-1>", movement)
- canvas.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement