为什么我的tkinter mainloop()
收到错误的命令名称canvas
错误?我正在创建一个AI棋盘游戏,并且创建了一个主循环。我将2个列表用于我的检查者ID:black_id
和white_id
,只是此处未列出:
def main_game_AI():
print("Read the README file first to learn how to move.")
move = input("What do you move?:")
checker_move = int(move)
where = input("What direction will you move?:")
canvas.move(black_id[checker_move],-23,-50)
print("Robot: OOOOOOoooooh!! Tricky decision! I play:")
canvas.move(white_id[3], -23,50)
white3 = 18
print("We start with the",first_side,"side.")
while gameOn == True:
main_game_AI()
root.destroy()
root.mainloop()
在我的循环中,运行main_game_AI()
,然后运行root.mainloop()
使tkinter gui正常工作。但是我必须使用root.destroy()
,所以循环继续进行。这在第一次迭代中效果很好。但是,当我在第二次迭代中输入测试输入时,出现了以下错误:
Traceback (most recent call last):
File "chineseCheckersAI.py", line 86, in <module>
main_game_AI()
File "chineseCheckersAI.py", line 77, in main_game_AI
canvas.move(black_id[checker_move],-23,-50)
File "/anaconda3/lib/python3.7/tkinter/__init__.py", line 2588, in move
self.tk.call((self._w, 'move') + args)
_tkinter.TclError: invalid command name ".!canvas"