Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-search-preview-high-loc· OpenAIHugging Face LMArena Search Arena 24K

Create me a python program with a resizable window, has a gui that is scales along with…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Perplexitysonar-reasoning-pro-high’s answer.
  1. User

    Create me a python program with a resizable window, has a gui that is scales along with the current window size, the button is square and it takes you to another page.

    And in the second page create another ui that has collapsible sidebar at the right which has a scale.

    Using pygame and pygame-menu libary

  2. Assistant

    To create a Python program using pygame and pygame-menu that features a resizable window with a GUI that scales with the window size, and includes a square button that navigates to another page with a collapsible sidebar containing a scale, follow the steps below:

    1. Install Required Libraries:

    Ensure you have pygame and pygame-menu installed. You can install them using pip:

    pip install pygame pygame-menu
    

    2. Create the Main Program Structure:

    We'll set up a resizable window and handle the GUI scaling accordingly.

    import pygame
    import pygame_menu
    from pygame.locals import RESIZABLE, VIDEORESIZE
    
    # Initialize pygame
    pygame.init()
    
    # Set initial window size
    WINDOW_SIZE = (800, 600)
    screen = pygame.display.set_mode(WINDOW_SIZE, RESIZABLE)
    pygame.display.set_caption('Resizable GUI with Pygame and Pygame-Menu')
    
    # Define colors
    WHITE = (255, 255, 255)
    BLACK = (0, 0, 0)
    
    # Function to handle window resizing
    def resize_window(event):
        global screen
        screen = pygame.display.set_mode((event.w, event.h), RESIZABLE)
        main_menu.resize(event.w, event.h)
    
    # Function to start the second page
    def start_second_page():
        second_page()
    
    # Create the main menu
    main_menu = pygame_menu.Menu('Main Menu', WINDOW_SIZE[0], WINDOW_SIZE[1],
                                 theme=pygame_menu.themes.THEME_BLUE)
    
    # Add a square button to the main menu
    button_size = min(WINDOW_SIZE) // 4  # Square button size
    main_menu.add.button('Go to Second Page', start_second_page, button_id='start_button')
    
    # Main loop
    running = True
    while running:
        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                running = False
            elif event.type == VIDEORESIZE:
                resize_window(event)
    
        screen.fill(WHITE)
        main_menu.update(events)
        main_menu.draw(screen)
        pygame.display.flip()
    
    pygame.quit()
    

    3. Create the Second Page with a Collapsible Sidebar:

    In the second page, we'll implement a collapsible sidebar on the right containing a scale (slider).

    def second_page():
        # Create a new menu for the second page
        second_menu = pygame_menu.Menu('Second Page', WINDOW_SIZE[0], WINDOW_SIZE[1],
                                       theme=pygame_menu.themes.THEME_DARK)
    
        # Add a slider (scale) to the sidebar
        slider = second_menu.add.range_slider('Adjust Value', 50, (0, 100), 1, value_format=lambda x: str(int(x)))
    
        # Function to toggle sidebar visibility
        sidebar_visible = True
    
        def toggle_sidebar():
            nonlocal sidebar_visible
            sidebar_visible = not sidebar_visible
            if sidebar_visible:
                second_menu.add_widget(slider)
            else:
                second_menu.remove_widget(slider)
    
        # Add a button to toggle the sidebar
        second_menu.add.button('Toggle Sidebar', toggle_sidebar)
    
        # Main loop for the second page
        running = True
        while running:
            events = pygame.event.get()
            for event in events:
                if event.type == pygame.QUIT:
                    pygame.quit()
                    return
                elif event.type == VIDEORESIZE:
                    resize_window(event)
    
            screen.fill(WHITE)
            second_menu.update(events)
            second_menu.draw(screen)
            pygame.display.flip()
    

    Explanation:

    • Resizable Window: The pygame.RESIZABLE flag allows the window to be resized. The resize_window function handles updating the display and menu sizes when the window is resized.

    • Main Menu: A square button is added to the main menu, which navigates to the second page when clicked. The button's size is determined based on the smaller dimension of the window to maintain its square shape.

    • Second Page: The second page features a collapsible sidebar on the right containing a slider. The toggle_sidebar function adds or removes the slider from the menu, effectively showing or hiding the sidebar.

    This setup ensures that the GUI elements scale appropriately with the window size and provides the desired navigation and interactive features.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.