python - 在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)
解决方案
关键是设置另一个默认值列表并将其作为另一个参数传递给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)
推荐阅读
- yaml - 别名覆盖标记为映射条目的错误缩进
- angular - 带有 Jest 的 Angular:因无法使用不同的导入找到提供者而失败的测试
- swift - 快速,通过按下按钮从 let 随机单词
- sh - 无法构建自定义 Slack 通知
- postgresql - 如何将 pg_monitor 角色添加到 heroku 上的 postgresql 用户
- swiftui - SwiftUI:@Environment 未在视图层次结构中接收提供的值
- javascript - 如何正确将此 C 代码编译为 WebAssembly?
- word-addins - Word加载项中如何获取段落的页码
- node.js - 为什么这个 ts 函数中参数的语法不正确?
- reactjs - 使用具有多个布尔字段的 Object 反应 useState