david_p
david_p

Reputation: 233

Set default values in easygui multienterbox

I have a struggle to find out how to set some default values into the fields of easygui multienterbox. Here is my code sample:

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)

Upvotes: 0

Views: 298

Answers (1)

david_p
david_p

Reputation: 233

The key was to set another list of default values and pass it as another parameter to multenterbox(). It was my random solution because I did not find this parameter anywhere in the documentation. Code sample here:

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)

Upvotes: 1

Related Questions