我想把 第一个用函数写出来 但是运行会出错 还请各位大佬斧正
import easygui as gmsg = "请输写以下联系方式"
title = "账号中心"
fieldName = ["*用户名" , "*真实姓名", "固有电话" , "*手机号码", "QQ" , "*E-mail"]
#x = []
x = g.multenterbox(msg , title , fieldName)
while True:
if x == None:
break
y = ""#相当于字符串
for i in range(len(fieldName)):
option = fieldName.strip()
if x.strip() == "" and option == "*":
y += ('(%s)为必填项。\n\n ' % fieldName)#字符串
if y =="":
break
x = g.multenterbox(msg = y , title = title , fields = fieldName, values = x)#field 是代表提示词value是代表输入的返回值
print("用户资料如下: %s" % str(x))
{:10_245:}
import easygui as g
def main(x , y):
while True:
if x == None:
break
#y = ""#相当于字符串
for i in range(len(fieldName)):
option = fieldName.strip()
if x.strip() == "" and option == "*":
y += ('(%s)为必填项。\n\n ' % fieldName)#字符串
return main
if y == "":
break
msg = "请输写以下联系方式"
title = "账号中心"
fieldName = ["*用户名" , "*真实姓名", "固有电话" , "*手机号码", "QQ" , "*E-mail"]
#x = []
x = g.multenterbox(msg , title , fieldName)
y = ""#相当于字符串
while True:
x = g.multenterbox(msg = main(x , y) , title = title , fields = fieldName, values = x)#field 是代表提示词value是代表输入的返回值
print("用户资料如下: %s" % str(x))
{:10_254:} 你得考虑变量的作用域,用函数写的时候尤其要注意,局部变量、全局变量,一个不小心就是很头疼的问题
你如果非要用函数写,我个人建议用类,通过类的属性来取代变量,比较优雅
页:
[1]