-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.py
More file actions
21 lines (18 loc) · 754 Bytes
/
Copy pathbutton.py
File metadata and controls
21 lines (18 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import pygame
class Button:
def __init__(self, x, y, width, height, text):
self.rect = pygame.Rect(x, y, width, height)
self.text = text
self.color = (255, 0, 0) # Red button
def draw(self, screen):
# Draw the button with the specified background color
pygame.draw.rect(screen, self.color, self.rect)
font = pygame.font.Font(None, 30)
text_render = font.render(self.text, True, (255, 255, 255))
text_rect = text_render.get_rect(center=self.rect.center)
screen.blit(text_render, text_rect)
def is_clicked(self, event):
if event.type == pygame.MOUSEBUTTONDOWN:
if self.rect.collidepoint(event.pos):
return True
return False