sand/button.py

32 lines
1.1 KiB
Python
Raw Normal View History

2024-02-23 19:35:20 +01:00
import pygame
class Button():
def __init__(self, screen, color, x, y, width, height, text) -> None:
self.pos = x,y
self.größe = width,height
self.color = color
self.screen = screen
self.text = text
def draw(self):
pygame.draw.rect(self.screen,
self.color,
(self.pos[0]-self.größe[0]//2,
self.pos[1]-self.größe[1]//2,
self.größe[0],
self.größe[1])
)
font = pygame.font.Font(None, 36)
text_surface = font.render(self.text, True, (0,0,0))
text_rect = text_surface.get_rect()
text_rect.center = (self.pos[0],
self.pos[1])
self.screen.blit(text_surface, text_rect)
def check_press(self, mouse):
if (self.pos[0] - self.größe[0]//2 <= mouse[0] <= self.pos[0] + self.größe[0]//2 and
self.pos[1] - self.größe[1]//2 <= mouse[1] <= self.pos[1] + self.größe[1]//2):
return True
else:
return False