-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttonClass.py
More file actions
27 lines (23 loc) · 879 Bytes
/
buttonClass.py
File metadata and controls
27 lines (23 loc) · 879 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
import pygame
class Button:
def __init__(self, x, y, width, height, color=(255, 135, 133), text=None, highlighted_color=(255, 203, 66),
functions=None, params=None
):
self.image = pygame.Surface((width, height))
self.pos = (x, y)
self.rect = self.image.get_rect()
self.rect.topleft = self.pos
self.color = color
self.text = text
self.highlighted_color = highlighted_color
self.functions = functions
self.params = params
self.highlighted = False
def update(self, mouse):
if self.rect.collidepoint(mouse):
self.highlighted = True
else:
self.highlighted = False
def draw(self, window):
self.image.fill(self.highlighted_color if self.highlighted else self.color)
window.blit(self.image, self.pos)