首页 > 解决方案 > 如何运行一个好的easygui选择框功能

问题描述

        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")

当我选择某些东西时,消息框就不会出来

标签: pythonpygameeasygui

解决方案


choicebox您正在针对您的字符串测试该函数。相反,针对您的字符串测试函数的结果。choicebox为了使其更清晰,请将其分配给一个choice变量。

        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")

推荐阅读