我在剧本的顶部写了下面的内容:
try:
from Tkinter import *
from Tkinter import messagebox
except ModuleNotFoundError:
from tkinter import *
from tkinter import messagebox
else:
print("tkinter error")
input()
sys.exit()
以.py或.pyw运行我的脚本可以正常运行。但是当我使用cx_Freeze创建和执行.exe时,exe会抛出错误:
那是为什么?怎么解决这个?
...谢谢
编辑: 还有我的setup.py:
import sys
import os
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = r"C:\Python\Python36-32\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = r"C:\Python\Python36-32\tcl\tk8.6"
base = None
executables = [Executable("toolbar.py", base=base)]
packages = []
options = {
'build_exe': {
'packages':packages,
},
}
setup(
name = "Desktop Toolbar",
options = options,
version = "1.0",
description = " ",
executables = executables
)