Search code examples
pythonpygameeasygui

How do I run a good easygui choicebox function


        if event.type == MOUSEBUTTONUP:
            mouseX, mouseY=event.pos
            if warsaw_button.collidepoint(mouseX,mouseY):
                choices = ["build a structure", "acquire units", "destroy structure", "launch from silo"]
                choicebox("What do you want to do commander?", warsaw_name, choices)
                if choicebox == choices[0]:
                    msgbox("you want to build a structure")
                elif choicebox == choices[1]:
                    msgbox("you want to acquire more units")
                elif choicebox == choices[2]:
                    msgbox("you want to destroy structures you built")
                elif choicebox == choices[3]:
                    msgbox("you want to launch missile from a silo")

When ever I choose something, the msgbox just wouldn't come out


Solution

  • You are testing the choicebox function against your strings. Instead, test the result of the choicebox function against your strings. To make it cleaner, assign it to a choice variable.

            if event.type == MOUSEBUTTONUP:
                mouseX, mouseY=event.pos
                if warsaw_button.collidepoint(mouseX,mouseY):
                    choices = ["build a structure", "acquire units", "destroy structure", "launch from silo"]
                    choice = choicebox("What do you want to do commander?", warsaw_name, choices)
                    if choice == choices[0]:
                        msgbox("you want to build a structure")
                    elif choice == choices[1]:
                        msgbox("you want to acquire more units")
                    elif choice == choices[2]:
                        msgbox("you want to destroy structures you built")
                    elif choice == choices[3]:
                        msgbox("you want to launch missile from a silo")