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_Diff(value, diff): print(value) print(diff) 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='', maxchar=99) mainmenu.add.button('Play', Start_The_Game) mainmenu.add.button('Levels', Level_Menu) mainmenu.add.button('Quit', pygame_menu.events.EXIT) Level = pygame_menu.Menu('Select a difficulty', 600, 400, theme=themes.THEME_BLUE) Level.add.selector('Difficulty :', [("Hard", 1), ("Easy", 2)], onchange=set_Diff) loading = pygame_menu.Menu("Loading the Game ...", 600, 400, theme=themes.THEME_BLUE) 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 pygame.time.set_timer(update_Loading, 1000) # Set up timer event to trigger update_Loading every second while True: events = pygame.event.get() for event in events: if event.type == update_Loading: progress = loading.get_widget("1") progress.set_value(progress.get_value() + 1) if progress.get_value() == 100: pygame.time.set_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()