在easygui multienterbox中设置默认值

Posted

技术标签:

【中文标题】在easygui multienterbox中设置默认值【英文标题】:Set default values in easygui multienterbox 【发布时间】:2021-12-23 00:10:19 【问题描述】:

我很难找出如何在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)

【问题讨论】:

【参考方案1】:

关键是设置另一个默认值列表并将其作为另一个参数传递给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)

【讨论】:

以上是关于在easygui multienterbox中设置默认值的主要内容,如果未能解决你的问题,请参考以下文章

[EasyGui]1. EasyGui的安装

python安装easygui

EasyGUI的安装

Easygui报错解决(仅解决easygui is not defined)

python学习EasyGui

在xib中设置accessibilityIdentifier nil时,必须从用户定义的运行时属性中设置