Tkinter错误消息 - 重绘按钮

时间:2017-05-24 06:00:56

标签: python-3.x tkinter graphics artificial-intelligence

我在Python3上下棋,使用Tkinter。我有bot模式的问题。玩家正确玩:点击按钮和数字移动。玩家的机器人应该玩之后。

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()(方法替换()的输入是正确的。我无法理解追溯

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"

如何解决问题? 附: log_field是每个单元条件的矩阵 字段是tkinter按钮的矩阵

1 个答案:

答案 0 :(得分:0)

你遇到问题:

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

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