Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 通过pyinstaller时程序未运行_Python_Python 3.x_Pyinstaller - Fatal编程技术网

Python 通过pyinstaller时程序未运行

Python 通过pyinstaller时程序未运行,python,python-3.x,pyinstaller,Python,Python 3.x,Pyinstaller,当我使用exit时,pyinstaller出现问题,出现错误,程序无法运行。当我使用quit或sys.exit()时,程序不会运行。如果我忽略所有这些,并使用X按钮,线程将在任务管理器中继续运行。我应该使用什么函数来修复此问题? 所需代码 def exitgame(): sys.exit() main = Tk() main.title("Fruit Clicker") main.geometry("400x350+300+100") B

当我使用
exit
时,pyinstaller出现问题,出现错误,程序无法运行。当我使用
quit
sys.exit()
时,程序不会运行。如果我忽略所有这些,并使用X按钮,线程将在任务管理器中继续运行。我应该使用什么函数来修复此问题? 所需代码

def exitgame():
    sys.exit()
    
main = Tk()
main.title("Fruit Clicker")
main.geometry("400x350+300+100")
Button(main, text="Play", command=rootopen).pack()
Button(main, text="Quit Game", command=exitgame).pack()

提前感谢

不用编写退出应用程序的函数,您可以不使用函数直接关闭应用程序,只需将“退出游戏按钮”的“command=exitgame”替换为“command=main.destroy”

示例代码-

from tkinter import * 
from tkinter.ttk import *
main = Tk()
main.title("Fruit Clicker")
main.geometry("400x350+300+100")
Button(main, text="Quit Game", command=main.destroy).pack()
mainloop()

您可以不使用函数直接关闭应用程序,而不用编写退出应用程序的函数,只需将“退出游戏按钮”的“command=exitgame”替换为“command=main.destroy”

示例代码-

from tkinter import * 
from tkinter.ttk import *
main = Tk()
main.title("Fruit Clicker")
main.geometry("400x350+300+100")
Button(main, text="Quit Game", command=main.destroy).pack()
mainloop()

这是返回的内容:
\u tkinter.TclError:无法调用“按钮”命令:应用程序已被销毁
@AnonymousPupper2006我已使用示例代码更新了我的答案,请尝试并让我知道这是返回的内容:
\u tkinter.TclError:无法调用“按钮”命令:应用程序已被销毁
@AnonymousPupper2006我已使用示例代码更新了我的答案,请尝试一下,并让我知道