Advertisement
snowden_web

Untitled

May 5th, 2019
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import tkinter
  3. import random
  4.  
  5. # constants
  6. WIDTH = 640
  7. HEIGHT = 480
  8. BG_COLOR = 'white'
  9.  
  10.  
  11. class Ball():
  12.     def __init__(self, x, y, r, color, dx = 0, dy = 0):
  13.         self.x = x
  14.         self.y = y
  15.         self.r = r
  16.         self.color = color
  17.         self.dx = dx
  18.         self.dy = dy
  19.    
  20.     def draw(self):
  21.         canvas.create_oval(self.x - self.r, self.y - self.r,  self.x + self.r, self.y + self.r, fill = self.color, outline = self.color)
  22.        
  23.  
  24. # mouse_events
  25. def mouse_click(event):
  26.     global main_ball
  27.     main_ball = Ball(event.x, event.y, 30, "blue")
  28.     main_ball.draw()
  29.  
  30.  
  31. #Окно игры
  32. root = tkinter.Tk()
  33. root.title("Война пончиков") #имя окошка
  34. canvas = tkinter.Canvas(root, width = WIDTH, height = HEIGHT, bg = BG_COLOR)
  35. canvas.bind('<Button-1>', mouse_click)
  36. canvas.pack()
  37. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement