-1

im making a restaurant management system and i want to disable a button and change its text to "Booked!" this is for the table booking system

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) 

I dont know what function to use. ive already got a name for it but idk what to put in it

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
DenM
  • 1
  • 3
  • Does this answer your question? [How to change Tkinter Button state from disabled to normal?](https://stackoverflow.com/questions/16046743/how-to-change-tkinter-button-state-from-disabled-to-normal) – wovano Oct 19 '22 at 11:37
  • i have tried the suggestion and it seems to not work for me it says "nonetype object does not support item assignment" – DenM Oct 19 '22 at 11:43
  • 2
    Then you didn't do it correctly. Or are you suggesting that the accepted answer with 77 upvotes is incorrect? Anyway, without a [mre] and full stacktrace we can't answer your question. – wovano Oct 19 '22 at 11:47

1 Answers1

0

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:

  1. Change Button State
  2. TypeError Solution
Hung
  • 155
  • 10