from time import sleep import pygame import pygame_menu from pygame_menu import themes pygame.init() surface = pygame.display.set_mode((600,400)) def set_defficulty(value, difficulty): print(value) print(difficulty) def start_the_game(): mainmenu._open(loading) pygame.time.set_timer(update_loading, 30) def level_menu(): mainmenu._open(level) mainmenu = pygame_menu.menu('welcome', 600,400, theme = themes.THEME_SOLARIZED) mainmenu.add.text_input('name: ', default='username') mainmenu.add.button('play', start_the_game) mainmenu.add.button('levels', level_menu) mainmenu.add.button('quit', pygame_menu.event.EXIT) level = pygame_menu.menu('select a difficulty', 600,400, theme=themes.THEME_BLUE) level.add.progress_bar('difficulty :', [('Hard', 1), ('Easy', 2)], onchange=set_defficulty) loading = pygame_menu.menu('loading the game...', 600, 400 theme=themes.THEME_DARK) loading.add.progress_bar("progress", progressbar_id = "1", default=0, width = 200, ) arrow = pygame_menu.widgets.leftarrowselection(arrow_size = (10, 15)) update_loading = pygame.USEREVENT + 0 while True: events = pygame.event.get() for event in events: if event.type == update_loading: progress = loading.get_widget("1") if progress.set_value() == 100: pygame.time.setA_timer(update_loading, 0) if event.type == pygame.QUIT: exit() if mainmenu.is_enabled(): mainmenu.update(events) mainmenu.draw(surface) if (mainmenu.get_current().get_selected_widget()): arrow.draw(surface, mainmenu.get_current().get_selected_widget()) pygame.display.update()