我在Python3上写国际象棋,用Tkinter。我对机器人模式有个问题。玩家正确发挥:点击按钮和人物移动。在玩家轮到机器人后,机器人应该可以玩了。
def main():
start_position()
root.mainloop()
while king_alive:
global bot_turn
if bot_turn:
cells = l.bot_move(log_field)
replace(cells[0], cells[1])
bot_turn = False这是函数replace(),用于更改字段中像元的条件
def replace(first_cell, second_cell):
if second_cell.figure.type != 'nofig':
delete_fig(second_cell.figure)
first_cell.clicked = False
second_cell.clicked = False
second_cell.fig_name = first_cell.fig_name
second_cell.fig_owner = first_cell.fig_owner
second_cell.figure = second_cell.get_figure()
first_cell.figure = l.NoFigure(first_cell.x, first_cell.y, "")
first_cell.fig_name = ""
first_cell.fig_owner = ""
field[second_cell.x][second_cell.y].configure(fg=second_cell.fig_owner, text=second_cell.fig_name)
field[first_cell.x][first_cell.y].configure(text="")
demark_cells()人们可以很容易地玩和移动人物,但机器人不能做到这一点,但是他使用相同的函数的移动-替换()(方法的输入替换()是正确的。我不能理解回溯
Traceback (most recent call last):
File "C:/Users/Даша/Desktop/python/task chess/graphics.py", line 176, in <module>
main()
File "C:/Users/Даша/Desktop/python/task chess/graphics.py", line 171, in main
replace(cells[0], cells[1])
File "C:/Users/Даша/Desktop/python/task chess/graphics.py", line 138, in replace
field[second_cell.x][second_cell.y]['fg'] = second_cell.fig_owner
File "C:\Python34\lib\tkinter\__init__.py", line 1275, in __setitem__
self.configure({key: value})
File "C:\Python34\lib\tkinter\__init__.py", line 1268, in configure
return self._configure('configure', cnf, kw)
File "C:\Python34\lib\tkinter\__init__.py", line 1259, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".36689776"如何解决这个问题?P.S. log_field是每个单元格的矩阵条件字段是按钮矩阵
发布于 2018-04-11 21:13:16
你在排队时遇到了一个问题:
field[second_cell.x][second_cell.y]['fg'] = second_cell.fig_owner因为您已经销毁或为在该行中调用的小部件分配了不同的变量。我不知道您的变量到底是什么,但它可能是field[second_cell.x][second_cell.y]['fg']或second_cell。
https://stackoverflow.com/questions/44150129
复制相似问题