SHARE
TWEET

Untitled

a guest Jun 18th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import tkinter
  2.  
  3. canvas = tkinter.Canvas(width="640", height="480")
  4. canvas.pack()
  5. square = canvas.create_rectangle(250, 250, 300, 300, fill="green")
  6. direction = 1
  7. def movement():
  8.     global direction
  9.     x1, y1, x2, y2 = canvas.coords(square)
  10.     print(x1, y1, x2, y2)
  11.     if y1 < 0:
  12.         direction = 1
  13.     if y2 > 480:
  14.         direction = -1
  15.     canvas.move(square, 0, (direction * 3))
  16.     canvas.after(50, movement)
  17.  
  18.  
  19. canvas.bind("<Button-1>", movement)
  20. canvas.mainloop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top