Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import tkinter
- import random
- # constants
- WIDTH = 640
- HEIGHT = 480
- BG_COLOR = 'white'
- class Ball():
- def __init__(self, x, y, r, color, dx = 0, dy = 0):
- self.x = x
- self.y = y
- self.r = r
- self.color = color
- self.dx = dx
- self.dy = dy
- def draw(self):
- 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)
- # mouse_events
- def mouse_click(event):
- global main_ball
- main_ball = Ball(event.x, event.y, 30, "blue")
- main_ball.draw()
- #Окно игры
- root = tkinter.Tk()
- root.title("Война пончиков") #имя окошка
- canvas = tkinter.Canvas(root, width = WIDTH, height = HEIGHT, bg = BG_COLOR)
- canvas.bind('<Button-1>', mouse_click)
- canvas.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement