From 9121342bffe429bfcbe4a15d8de49e5e3cfe7135 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sat, 20 Apr 2024 15:55:49 +0200 Subject: [PATCH] Made the TextButton a pygame.sprite.Sprite. --- pg.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pg.py b/pg.py index 892bd7d..4fe1c77 100644 --- a/pg.py +++ b/pg.py @@ -74,11 +74,13 @@ class Button: return False -class TextButton: +class TextButton(pygame.sprite.Sprite): """ Creates a button from just some string and a position. """ def __init__(self, text: str, position: tuple, function=None, args: tuple=None, key: int=0, text_color: tuple=white, bg_color: tuple=gray, font: pygame.font.Font=default_font, padding: tuple=(8, 8), border_radius: int=0, line_thickness: int = 0): + pygame.sprite.Sprite.__init__(self) + self.text = text self.position = position self.text_color = text_color @@ -91,7 +93,7 @@ class TextButton: self.border_radius = border_radius self.line_thickness = line_thickness - self.surface, self.size = self.generate_surface() + self.image, self.size = self.generate_surface() self.rect = self.make_rect() self.button = Button(self.rect, self.function, args, self.key) @@ -113,7 +115,7 @@ class TextButton: return pygame.Rect(self.position, self.size) def draw(self, surface: pygame.Surface): - surface.blit(self.surface, self.position) + surface.blit(self.image, self.position) def check(self, mouse_pos, pressed): return self.button.check(mouse_pos, pressed)