首页 > 解决方案 > 在easygui multienterbox中设置默认值

问题描述

我很难找出如何在 easygui multienterbox 的字段中设置一些默认值。这是我的代码示例:

from easygui import multenterbox

msg = "Enter your personal information"
title = "Form"
fieldNames = ["Name", "Street Address", "City", "State", "ZipCode"]
fieldValues = multenterbox(msg, title, fieldNames)

# make sure that none of the fields was left blank
while 1:
    if fieldValues == None: break
    errmsg = ""
    for i in range(len(fieldNames)):
        if fieldValues[i].strip() == "":
            errmsg = errmsg + ('"%s" is a required field.\n\n' % fieldNames[i])
    if errmsg == "": break  # no problems found
    fieldValues = multenterbox(errmsg, title, fieldNames, fieldValues)
print("Reply was:", fieldValues)

标签: pythonparametersdefault-valueeasygui

解决方案


关键是设置另一个默认值列表并将其作为另一个参数传递给multenterbox(). 这是我的随机解决方案,因为我在文档中的任何地方都没有找到这个参数。代码示例在这里:

from easygui import multenterbox

msg = "Enter your personal information"
title = "Form"
fieldNames = ["Name", "Street Address", "City", "State", "ZipCode"]
fieldNames_defs = ["Dave", "Narrow st.", "Prague", "CZE", "18000"]
fieldValues = multenterbox(msg, title, fieldNames, fieldNames_defs)

# make sure that none of the fields was left blank
while 1:
    if fieldValues == None: break
    errmsg = ""
    for i in range(len(fieldNames)):
        if fieldValues[i].strip() == "":
            errmsg = errmsg + ('"%s" is a required field.\n\n' % fieldNames[i])
    if errmsg == "": break  # no problems found
    fieldValues = multenterbox(errmsg, title, fieldNames, fieldValues)
print("Reply was:", fieldValues)

推荐阅读