首页 > 解决方案 > 单击时如何禁用Tkinter按钮

问题描述

因此,我试图在单击时禁用按钮,因为我只需要执行一次操作,在这种情况下,打印(“单击按钮”)。我不希望用户再次单击该按钮。使用此代码:

board = tk.Tk()
game.geometry("200x200")

def click():
    print("button clicked")
    button["state"] = tk.DISABLED

button = tk.Button(board, text="click to disable", command=click).place(x=100, y=100)

board.mainloop()

我不断收到错误消息:TypeError:'NoneType' 对象不支持项目分配。

我在这里错过了什么吗?如何禁用此按钮?

标签: python-3.xtkintertkinter-button

解决方案


推荐阅读