Git Product home page Git Product logo

Comments (3)

ALfahi avatar ALfahi commented on June 12, 2024

never mind; I have found a solution due to the previous enhancements:
the solution was to make the button read-only and then change it with if statements.
Thank you for this wonderful pip installation

from pygame-menu.

ppizarror avatar ppizarror commented on June 12, 2024

I arrived late, but check the following example I just did:

import random
import pygame
import pygame_menu

pygame.init()
screen = pygame.display.set_mode((640, 480))
theme = pygame_menu.themes.THEME_BLUE.copy()
theme.widget_margin = (0, 5)
menu = pygame_menu.Menu('Button disable', 640, 480, theme=theme)


def check_name(name_value: str = '') -> None:
    """
    Checks the name, which updates the button.
    For complex mechanisms, you can use a class to store the name variable
    instead of accesing global ones (like this case).

    :param name_value: Value passed from onchange() text input method
    """
    global button
    name_ready = name_value != ''
    print('User not configured yet' if not name_ready else 'User ready!')
    button.readonly = not name_ready
    button.set_selection_effect(None if not name_ready else theme.widget_selection_effect)


def game() -> None:
    """
    Starts the game, this method only changes the background color of the menu.
    """
    print('Game started!')
    menu.get_scrollarea().update_area_color((random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))


# Create a basic input
name = menu.add.text_input('Enter your name: ', onchange=check_name)
button = menu.add.button('Play', game)
menu.add.button('Exit', pygame_menu.events.EXIT)

# Call start game to setup the initial status, it retrieves the name (which is empty at the app start),
# and disables the button by setting readonly, also dynamically updates the selection effect
check_name()
menu.mainloop(surface=screen)

This example retrieves the input and changes the color of the background color of the "menu area".

from pygame-menu.

ALfahi avatar ALfahi commented on June 12, 2024

from pygame-menu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.