Tkinter 错误消息 - 重绘按钮



我在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()

人们可以轻松地玩和移动人物,但机器人不能做到这一点,但是他使用相同的移动函数 - replace(((方法replace((的输入是正确的。我无法理解回溯

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:Python34libtkinter__init__.py", line 1275, in __setitem__
    self.configure({key: value})
  File "C:Python34libtkinter__init__.py", line 1268, in configure
    return self._configure('configure', cnf, kw)
  File "C:Python34libtkinter__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场是每个细胞条件的矩阵字段是 tkinter 按钮的矩阵

您在以下行中有问题:

field[second_cell.x][second_cell.y]['fg'] = second_cell.fig_owner

因为您已经销毁或为该行中调用的小部件分配了不同的变量。我不知道你的变量到底是什么,但它可能是field[second_cell.x][second_cell.y]['fg']second_cell.

相关内容

  • 没有找到相关文章

最新更新