multpasswordbox密码访问出错
import easygui as gimport string as s
import random
a = s.ascii_letters+s.digits
def getKey():# 产生随机字符串
key=random.sample(a,10)
keys="".join(key)
return keys
msg = '请输入账户和密码:'
title = '登录账号'
filed_name = ['用户名:','密码:']
while 1:
password = ''
temp = g.multpasswordbox(msg ,title,filed_name)
if temp == None:
break
elif temp == '' or temp != '' and temp == '':
g.msgbox('密码错误,请重新输入!')
elif temp == '52154615':
password = '12345678'
if temp == password:
g.msgbox('密码正确!')
break
else:
g.msgbox('密码错误,请重新输入!')
print('用户名:%s' % temp)
print(('密码提示:%s···' % password[:4]))
elif temp is not ['77444445','961182830','52154615']:
password = getKey()# 调用获取随机密码的函数
count = 3
while count > 0:
temp = g.multpasswordbox(msg, title, filed_name)
if temp == password:
g.msgbox('密码正确!')
break
else:
g.msgbox('密码错误,请重新输入!')
print('用户名:%s' % temp)
print(('密码提示:%s···' % password[:4]))
count -= 1
萌新求问时间:
TypeError: 'NoneType' object is not subscriptable
每次输入不是['77444445','961182830','52154615']这三个账号的时候,密码如果输错了,返回登录界面然后cancel 就会报错 第40行(红色字体那行)没有判断第39行返回temp为None的情况(点取消返回None)。 hrp 发表于 2021-4-2 00:51
第40行(红色字体那行)没有判断第39行返回temp为None的情况(点取消返回None)。
我在39行和40行之间加了
if temp == None:
break
hrp 发表于 2021-4-2 00:51
第40行(红色字体那行)没有判断第39行返回temp为None的情况(点取消返回None)。
这样可以跳出小循环,但是不能跳出大循环,这样就需要2次cancel,有没有办法可以避免呢 hrp 发表于 2021-4-2 00:51
第40行(红色字体那行)没有判断第39行返回temp为None的情况(点取消返回None)。
解决了,在大循环最后一行加个 break 就好了,谢谢了
页:
[1]