Solution to change text and state:
You can change the button by using state
.
Table1['state'] = DISABLED
or Table1.config(state=DISABLE)
Note: To disable a button, use DISABLE
, to enable it again, use NORMAL
.
Use the same method to change the text.
Table1['text'] = 'something'
or Table1.config(text='something')
Solution for the TypeError:
The reason why the error:
TypeError: 'NoneType' object does not support item assignment
is raised is because you used .grid()
when declaring Table1
:
Table1 = Button(f1ab, padx=16, pady=1, bd=4, fg="black",font=("Clarity Gothic SF", 16, "bold"), width=5,
text="Table 1", command=button_click).grid(row=0, column=0)
You can just fix it by separating that line into 2:
Table1 = Button(f1ab, padx=16, pady=1, bd=4, fg="black",font=("Clarity Gothic SF", 16, "bold"), width=5,
text="Table 1", command=button_click)
Table1.grid(row=0, column=0)
The code should be:
The function:
def button_click():
Table1['state'] = DISABLED
Table1['text'] = 'Booked!'
Full code:
from tkinter import *
f1ab = Tk()
def button_click():
Table1['state'] = DISABLED
Table1['text'] = 'Booked!'
Table1 = Button(f1ab, padx=16, pady=1, bd=4, fg="black", font=("Clarity Gothic SF", 16, "bold"), width=5,
text="Table 1", command=button_click)
Table1.grid(row=0, column=0)
mainloop()
For more detail, visit:
- Change Button State
- TypeError Solution