-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.py
27 lines (23 loc) · 888 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
import pygame
# this is a button class to make coding the buttons easier
class Button:
def __init__(self, text, x, y, color):
self.text = text
self.x = x
self.y = y
self.color = color
self.width = 200
self.height = 100
def draw(self, win):
pygame.draw.rect(win, self.color, (self.x, self.y, self.width, self.height))
font = pygame.font.SysFont("comicsans", 40)
text = font.render(self.text, 1, (255, 255, 255))
win.blit(text, (self.x + round(self.width / 2) - round(text.get_width() / 2),
self.y + round(self.height / 2) - round(text.get_height() / 2)))
def click(self, pos):
x1 = pos[0]
y1 = pos[1]
if self.x <= x1 <= self.x + self.width and self.y <= y1 <= self.y + self.height:
return True
else:
return False