我正在尝试将tkinter项目转换为exe,但是当我运行setup.py时出现此错误:
Traceback (most recent call last):
File "C:\Users\Tiago\Desktop\Python\Calculator\setup.py", line 7, in <module>
options={"build_exe":{"packages":[tkinter],"include_files":["Calculator.ico"]}},
NameError: name 'tkinter' is not defined
有人可以说我的代码有什么问题吗?
import cx_Freeze
executables=[cx_Freeze.Executable("Calculator.pyw")]
cx_Freeze.setup(
name="Calculator",
options={"build_exe":{"packages":[tkinter],"include_files":["Calculator.ico"]}},
description = "Calculator",
executables = executables
)
答案 0 :(得分:0)
您应该使用"tkinter"
代替tkinter
。
但是在大多数情况下,如果您在脚本中以正常方式导入tkinter
,则会自动包含tkinter。因此,您只需删除"packages":["tkinter"]
。
顺便说一下,您可能需要以这种方式将可执行文件声明为Win32GUI
程序:
executables=[cx_Freeze.Executable("Calculator.pyw", base='Win32GUI')]