用python画界面,通过button退出程序时,在ide使用中没有问题,但是封装成应用程序时就出现问题。源代码:
btn3 = Button(root, text='退出', command=exit)
报错:
NameError: name ‘exit’ is not defined
解决方法:
1、import sys
2、将代码改为
btn3 = Button(root, text='退出', command=sys.exit)
就成功了
顺带一提,python打包exe方法:
1、安装pyinstaller,命令行 --> pip install pyinstaller
2、输入命令:pyinstaller -F (py文件路径).py
生成的exe文件位置会显示出来