NameError:未在cx\u python中定义“退出”

2024-06-14 03:22:42 发布

您现在位置:Python中文网/ 问答频道 /正文

编辑

以下是我的GUI代码:

from tkinter import *
import builtins as bi

root = Tk()
root.title("hello worlds")

btn = Button(root, text="hello worlds", command=bi.exit)
btn.pack()

root.mainloop()

这就是setup.py

import cx_Freeze as cf
import sys

executable = [cf.Executable("asd.py")]

cf.setup(
    name = "asd",
    executables = executable,
    options = {"build_exe" : {"packages" : ["tkinter"]}}
)

当我构建脚本时,它工作正常,但当我运行可执行文件时,它会显示一个错误:

AttributeError: module 'builtins' has no attribute 'exit'

此外,我不能使用其他内置函数,我已尝试重新定义退出函数。但它也显示了一个错误:

RecursionError: maximum recursion depth exceeded

我如何解决这个问题


Tags: pyimporthellotkinterassetupexitroot