-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.py
More file actions
31 lines (23 loc) · 765 Bytes
/
Button.py
File metadata and controls
31 lines (23 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pygame
class Button:
def __init__(self, x, y, image, screen):
self.screen = screen
self.image = image
self.rect = self.image.get_rect()
self.rect.x = x // 2 - 240
self.rect.y = y // 2 - 70
self.clicked = False
def draw(self):
f = False
# Мышка
pos = pygame.mouse.get_pos()
# Проверка
if self.rect.collidepoint(pos):
if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False:
f = True
self.clicked = True
if pygame.mouse.get_pressed()[0] == 0:
self.clicked = False
# отрисовка кнопки
self.screen.blit(self.image, self.rect)
return f