【问题标题】:Set default values in easygui multienterbox在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)

【问题讨论】:

    标签: python parameters default-value easygui


    【解决方案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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多