Set default values in easygui multienterbox

235 Views Asked by At

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)
1

There are 1 best solutions below

0
david_p On

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)