diff options
| author | Moisis <moisis.george@yahoo.com> | 2023-04-24 01:27:30 +0200 |
|---|---|---|
| committer | Moisis <moisis.george@yahoo.com> | 2023-04-24 01:27:30 +0200 |
| commit | 1c33c06df4d40e708d526cd00d3b8392d931b7c2 (patch) | |
| tree | 100233aede0f4071b957e9fe047a4f96400323d7 /src/GUIbutton.py | |
| parent | 7194ca65ae23d96960fe7edb619efb100db0a49c (diff) | |
| download | Macpan-1c33c06df4d40e708d526cd00d3b8392d931b7c2.tar.xz Macpan-1c33c06df4d40e708d526cd00d3b8392d931b7c2.zip | |
Added Basic GUI
Diffstat (limited to 'src/GUIbutton.py')
| -rw-r--r-- | src/GUIbutton.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/GUIbutton.py b/src/GUIbutton.py new file mode 100644 index 0000000..794f693 --- /dev/null +++ b/src/GUIbutton.py @@ -0,0 +1,29 @@ +class Button(): + def __init__(self, image, pos, text_input, font, base_color, hovering_color): + self.image = image + self.x_pos = pos[0] + self.y_pos = pos[1] + self.font = font + self.base_color, self.hovering_color = base_color, hovering_color + self.text_input = text_input + self.text = self.font.render(self.text_input, True, self.base_color) + if self.image is None: + self.image = self.text + self.rect = self.image.get_rect(center=(self.x_pos, self.y_pos)) + self.text_rect = self.text.get_rect(center=(self.x_pos, self.y_pos)) + + def update(self, screen): + if self.image is not None: + screen.blit(self.image, self.rect) + screen.blit(self.text, self.text_rect) + + def checkForInput(self, position): + if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom): + return True + return False + + def changeColor(self, position): + if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom): + self.text = self.font.render(self.text_input, True, self.hovering_color) + else: + self.text = self.font.render(self.text_input, True, self.base_color)
\ No newline at end of file |
