计算在没有装饰器的情况下单击按钮的次数(Python)

时间:2016-12-15 01:25:06

标签: python-3.x tkinter

所以我正在用tkinter做一个tic tac toe游戏。但是,当我提高转弯值时,我得到一个属性错误:'function'对象没有属性'called'。我这样做是因为计算机不会跳过它

def player_move(widget):
    if widget["o"] not in ("o", "x"):
        widget["text"] = "o"
        widget["state"] = "disabled"
        player_move.called += 1  #The part I want to add to
        computer_move()

def computer_move():
    # computer moves 2nd time
    if i["text"] == "  ":
        i["text"] = "x"
        i["state"] = "disabled"
    else:
        c["text"] = "x"
        c["state"] = "disabled"
    if player_move.called == 1 and c["text"] == "x":
        print("whgwhgg") #Just for testing

1 个答案:

答案 0 :(得分:0)

首先,您需要在为此变量添加+1之前创建具有某个值的'pv'(但在创建函数player_move.called后创建它)

player_move()