-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.py
31 lines (25 loc) · 890 Bytes
/
button.py
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 read_config
import pygame
BLACK,WHITE,GRAY=read_config.read_config()
COLOR_INACTIVE = WHITE
COLOR_ACTIVE= GRAY
class Button:
def __init__(self, x, y, w, h, text_x, text=''):
FONT = pygame.font.Font(None, 32)
self.rect = pygame.Rect(x, y, w, h)
self.text = text
self.txt_surface = FONT.render(text, True, BLACK)
self.click=False
self.text_x=text_x
def handle_event(self, event):
if event.type == pygame.MOUSEBUTTONDOWN:
# If the user clicked on the button
if self.rect.collidepoint(event.pos):
self.click=True
else:
self.click=False
def draw(self, screen):
# Blit the text.
screen.blit(self.txt_surface, (self.rect.x+self.text_x, self.rect.y+15))
# Blit the rect.
pygame.draw.rect(screen, BLACK, self.rect, 2)