关闭窗口的时候报错。
本帖最后由 python羊 于 2020-3-17 14:50 编辑运行的时候没有问题,当点击右上角的 X 关闭,或者点击 ‘CANCEL’关闭该程序的时候报错
代码如下:
————————————————————————————————————————————
import easygui as g
import sys
name_aidekang = '康,ADK'
name_aidr = '尔,ADE'
name_aideyang = '扬,ADY'
msg = '输入名称'
title = '客户要求'
name = g.enterbox(msg,title)
while True :
if name in name_aidekang:
g.msgbox('找到了ADK。康')
name = g.enterbox(msg,title)
elif name in name_aidr:
g.msgbox('找到了ADE 尔')
name = g.enterbox(msg,title)
elif name in name_aideyang :
g.msgbox('找到了ADY 扬')
name = g.enterbox(msg,title)
else:
g.msgbox('未查询到此客户')
name = g.enterbox(msg,title)
————————————————————————————————————————————
报错内容:
——————————————————————————————————————————————————————
>>>
Traceback (most recent call last):
File "C:/Users/PC-19/Desktop/实验室助手/实验室助手1.0 测试.py", line 13, in <module>
if name in name_aidekang:
TypeError: 'in <string>' requires string as left operand, not NoneType
>>>
>>>
——————————————————————————————————————————————
布尔类型 True和False
while循环的条件,你写错了,首字母应该大写 sunrise085 发表于 2020-3-17 14:33
布尔类型 True和False
while循环的条件,你写错了,首字母应该大写
谢谢您。我改过来了。还是报错:
============= RESTART: C:/Users/PC-19/Desktop/实验室助手/实验室助手1.0 测试.py =============
Traceback (most recent call last):
File "C:/Users/PC-19/Desktop/实验室助手/实验室助手1.0 测试.py", line 13, in <module>
if name in name_aidekang:
TypeError: 'in <string>' requires string as left operand, not NoneType
>>> python羊 发表于 2020-3-17 14:49
谢谢您。我改过来了。还是报错:
============= RESTART: C:/Users/PC-19/Desktop/实验室助手/实验室 ...
你是完全不会看这些错误提示吗?
TypeError: 'in <string>' requires string as left operand, not NoneType
这是说你的语句if name in name_aidekang:中in左侧的变量name类型不对。
你看一下name = g.enterbox(msg,title)enterbox的返回值是什么类型。应该是需要类型转换 sunrise085 发表于 2020-3-17 14:55
你是完全不会看这些错误提示吗?
TypeError: 'in ' requires string as left operand, not NoneType
我明白了,为什么选择cancel 或者 直接关闭 都会报错了。因为 g.enterbox()的 cancel 和 关闭返回值是 :True。
感谢大佬
页:
[1]