使用multenterboxes - EasyGui

时间:2016-06-01 13:17:59

标签: python easygui

我正在使用easygui |蟒。

import easygui as eg
fields = ["juvenile","adult","senile"];
message = "Please fill in the boxes";
windowtitle = "set generation values";
while True:
    inputvalues = eg.multenterbox(message, windowtitle, fields);
    valid = True;
    if inputvalues == None:
        eg.msgbox("You did not fill out the boxes!", "error");
        continue;
    for value in inputvalues:
        if value == "":
            valid = False;
            break;
    if valid == True:
        break;
    else:
        eg.msgbox("You did not fill in one of the boxes!", "error");

这是我制作的multenter盒子。我需要有关如何使用multenter框中的值的帮助。例如:

if juvenile == 100:
    eg.msgbox("there are 100 juveniles in your population")

这部分代码没有回应,有人知道解决方案吗?

2 个答案:

答案 0 :(得分:1)

我认为您的问题是您尝试检查juvenile是否为int,但multenterbox会返回字符串列表。

所以也许这会解决它:

if juvenile=="100":
    eg.msgbox("there are 100 juveniles in your population")

答案 1 :(得分:0)

因为Easygui返回List,所以请使用rescriptable(我不知道它叫什么,但我叫它!)函数,我的意思是[start, end, (action)]

因此,因为juvenile是第一个,所以我们将这样做:

if inputvalues[0] == "100":  # It needs to be `0` in `[]` because it means first. Second is `1` and continue
    # Do something

然后继续