gorskaja2019

Untitled

Apr 24th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. from tkinter import*
  2. from random import *
  3. from time import *
  4.  
  5. class Ball:
  6. def __init__(self, canvas, color):
  7. self.canvas = canvas
  8. self.id = canvas.create_oval(10,10,25,25,fill=color)
  9. self.canvas.move(self.id, 225, 180)
  10. self.x = 1
  11. self.y = 0
  12.  
  13. def draw(self):
  14. self.canvas.move(self.id, self.x, self.y)
  15. (x1, y1, x2, y2) = self.canvas.coords(self.id)
  16. if x2 >= self.canvas.winfo_width():
  17. self.x=-1
  18. if x1 <= 0:
  19. self.x=1
  20.  
  21. root = Tk()
  22. root.title('Пинг-понг')
  23. canvas = Canvas(width = 500, height = 400, bg = 'deepskyblue')
  24. canvas.pack()
  25.  
  26. ball = Ball(canvas, 'red')
Advertisement
Add Comment
Please, Sign In to add comment