1
0
Fork 0

Added quit button

This commit is contained in:
Michał Rudowicz 2024-09-08 16:50:18 +02:00
parent 7084a51b0a
commit 0ab21fabc0
1 changed files with 8 additions and 3 deletions

11
menu.py
View File

@ -11,6 +11,7 @@ import pygame.freetype
class ButtonDef(TypedDict):
text: str
cbk: Callable[[], None]
class IBoard:
@ -68,7 +69,7 @@ class MenuBoard(IBoard):
button_positions = self.generate_button_positions(screen_rect)
self.buttons = list(map(lambda d: Button(next(button_positions),
f"Button {d['text']}",
lambda: print(d['text'])), buttons))
d['cbk']), buttons))
def generate_button_positions(self, screen_rect: pygame.Rect):
current_button_row = 0
@ -102,8 +103,9 @@ class App:
self.screen = pygame.display.set_mode((info.current_w, info.current_h), flags=pygame.FULLSCREEN)
self.clock = pygame.time.Clock()
self.running = False
self.board: IBoard = MenuBoard(pygame.Rect(0, 0, info.current_w, info.current_h),
list(map(lambda t: ButtonDef(text=f"{t}"), list(range(btns)))))
buttons = list(map(lambda t: ButtonDef(text=f"{t}", cbk=lambda: print(t)), list(range(btns))))
buttons.append(ButtonDef(text="Exit", cbk=self.quit))
self.board: IBoard = MenuBoard(pygame.Rect(0, 0, info.current_w, info.current_h), buttons)
def loop(self):
self.running = True
@ -122,6 +124,9 @@ class App:
self.clock.tick(30)
pygame.quit()
def quit(self):
self.running = False
if __name__ == '__main__':
app = App(int(sys.argv[1]))