这是我的代码:
#Game Restart Func
def restart_program():
for widget in root.winfo_children():
widget.destroy()
button = Button(root, text='Stop', width=25, command=root.destroy)
button.pack()
b1 = Button(root, text="Restart", command=restart_program)
b1.pack()
g = GalagaGame(root)
root.after(10, g.gameLoop())
root.mainloop()
此功能是重启游戏的功能 主要功能就是这样写的
root = Tk()
button = Button(root, text='Stop', width=25, command=root.destroy)
button.pack()
b1 = Button(root, text="Restart", command=restart_program)
b1.pack()
g = GalagaGame(root)
root.after(10, g.gameLoop())
root.mainloop()
但仍有奇怪的错误。
Tkinter回调中的异常
Traceback (most recent call last):
File "C:\Users\Kim Donguk\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:\Users\Kim Donguk\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 745, in callit
func(*args)
File "C:\Users\Kim Donguk\Desktop\Game project\game_source\game.py", line 281, in gameLoop
self.paint(self.canvas)
File "C:\Users\Kim Donguk\Desktop\Game project\game_source\game.py", line 260, in paint
self.canvas.delete(ALL)
File "C:\Users\Kim Donguk\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 2508, in delete
self.tk.call((self._w, 'delete') + args)
_tkinter.TclError: invalid command name ".!canvas"
如何解决此错误?