-1

I created a checkbox that will be used to enable/disable its corresponding entry.

b1var = IntVar(value=1)
b1 = Checkbutton(bevmenu, command=lambda: check(), text="Latte", variable=b1var, onvalue=1, offvalue=0).grid(row=0, column=0, sticky="w")
b1a = Entry(bevmenu, bd=2, textvariable=b1v, state=DISABLED).grid(row=0, column=1, sticky="w")

Here's the function that will perform the enabling/disabling of the entry:

def check():
    if b1var.get() == 1:
        b1a.config(state=NORMAL)
    elif b1var.get() == 0:

I tried running the program and not only that it doesn't work, it also gives this output error when I try to check/uncheck.

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\__\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1884, in __call__
    return self.func(*args)
  File "C:\Users\__\PycharmProjects\CafeManagementSystem\main.py", line 96, in <lambda>
    b1 = Checkbutton(bevmenu, command=lambda: check(), text="Latte", variable=b1var, onvalue=1, offvalue=0)
  File "C:\Users\__\PycharmProjects\CafeManagementSystem\main.py", line 23, in check
    b1a.config(state=DISABLED)
AttributeError: 'NoneType' object has no attribute 'config'
Sieg
  • 31
  • 5

1 Answers1

0

Replace:

b1a = Entry(bevmenu, bd=2, textvariable=b1v, state=DISABLED).grid(row=0, column=1, sticky="w")

with:

b1a = Entry(bevmenu, bd=2, textvariable=b1v, state=DISABLED)
b1a.grid(row=0, column=1, sticky="w")

I don't think the function grid returns anything (in mathematics, a function returns a value - and in programming if it does not, it's a method that just performs a task. So grid is just a method that sets the layout, it does not return anything. Read more here) (:

More examples here.

Rikki
  • 3,338
  • 1
  • 22
  • 34
  • My bad. Should I replace entry's .grid with .pack? The problem is I don't know how to arrange them. – Sieg Feb 20 '21 at 03:50
  • As I said, do the replacement as mentioned in the answer. First you call Entry, and b1a will contain the Entry instance. Then you call grid on b1a (which contains the Entry instance). Does that help? – Rikki Feb 20 '21 at 03:53