MoDieSse
MoDieSse

Reputation: 1

Guizero PushButton with command parameter doesn't wait action

I'm trying to build a menu with buttongroup to let the user choose the function to execute, to be confirmed by pressing a button with pushbutton, but executing the code funzione1 is executed immediately without waiting for the choice. I think the problem is in the "command" parameter of PushButton, which is executed even if the button is not pressed; or something else?

My code:

from guizero import App, Text, ButtonGroup, PushButton

def MainMenu():
    app = App(title="Titolo")

    def semen(menu):
        if ((menu >= 0) and (menu <= 2)):
            if menu == 1:
                Funzione1()
            elif menu == 2:
                Funzione2()
            elif menu == 0:
                    # Uscita
                print(0)
                return False

    text_1 = Text(app, text=" ")
    text_2 = Text(app, text="Cosa vuoi fare?")
    text_1 = Text(app, text=" ")
    choice = ButtonGroup(app, options=[
        ["Funzione1", 1],
        ["Funzione2", 2],
        ["Chiudere e uscire", 0]])
    text_1 = Text(app, text=" ")
    button = PushButton(app, command=(semen(int(choice.value))), text="Seleziona")
    app.display()

def Funzione1():
    print('Eseguo funzione1')

def Funzione2():
    print('Eseguo funzione2')

MainMenu()

PushButton without "command" parameter, nothing happen

Upvotes: 0

Views: 213

Answers (1)

Tim A
Tim A

Reputation: 1

You should try this:

button = PushButton(app, command=semen, args=int(choice.value), text="Seleziona")

Upvotes: 0

Related Questions