Feb-16-2022, 05:25 PM
The method checkboxes.addCheckBox returns an IntVar. It does not return a Checkbutton. You cannot disable an IntVar.
Your method checkboxes.chkbxClick is a mess. You must have a lot of global variables because all of the variables used here are undefined.
My guess is somewhere you do this:
What is the checkboxes class supposed to do? As is, it doesn't appear to do anything other than define two functions. Here's an example that creates a Checkbox class that is a tk.Checkbutton with some extra features.
Your method checkboxes.chkbxClick is a mess. You must have a lot of global variables because all of the variables used here are undefined.
My guess is somewhere you do this:
root = Tk() boxes = checkboxes(root) chkbxItemCard = boxes.addCheckBox(..., cmd=boxes.chkbxClick)chkbxItemCard is an IntVar. When you try to disable the IntVar you get an error because IntVar does not disable.
What is the checkboxes class supposed to do? As is, it doesn't appear to do anything other than define two functions. Here's an example that creates a Checkbox class that is a tk.Checkbutton with some extra features.
import tkinter as tk class Checkbox(tk.Checkbutton): """I add an IntVar to a check button""" var_types = {bool:tk.BooleanVar, int:tk.IntVar, float:tk.DoubleVar} def __init__(self, parent, x, y, onvalue=1, offvalue=0, **kwargs): self.variable = self.var_types.get(type(onvalue), tk.StringVar)(value=offvalue) super().__init__(parent, variable=self.variable, onvalue=onvalue, offvalue=offvalue, **kwargs) self.place(x=x, y=y) def value(self): return self.variable.get() def set_value(self, value): self.variable.set(value) class App(tk.Tk): def __init__(self, title=None, geometry="250x120", **kwargs): super().__init__(**kwargs) if geometry is not None: self.geometry(geometry) if title is not None: self.wm_title(title) self.printer = Checkbox(self,10, 10, text="Printer") self.printer.config(command=lambda: print(self.printer.value())) self.setter = Checkbox(self, 10, 50, text="Setter") self.setter.config(command=lambda: self.printer.set_value(self.setter.value())) self.enabler = Checkbox(self, 10, 90, text="Disabler", onvalue="disabled", offvalue="normal") self.enabler.config(command=lambda: self.printer.config(state=self.enabler.value())) app = App("Checkboxes") app.mainloop()