From what I've been able to find in internet tutorials, the Checkbutton has a command
option. So, either this is incorrect, or I am stumped as to how to use the option. What I'm trying to do is to have a text Entry box be gray (disabled
) when the Checkbutton is not checked, and to enable the text Entry box when the Checkbutton is checked.
My code: class OutputSettings: def init(self, master):
frame = LabelFrame(master, text = 'Debug')
frame.grid(row=2, column=0, columnspan = 2)
self.make_txt = BooleanVar()
self.make_txt.set(True)
self.create_a_file = Checkbutton(frame, text = 'Create Text File')
self.create_a_file.config(variable = self.make_txt,
command = self.graytextbox())
self.create_a_file.pack()
Label(frame,
text="Text File \nSave Location:",
font = "Verdana 8").pack()
self.file_location = StringVar()
self.file_location = Entry (frame, width=30, textvariable = self.file_location)
self.file_location.pack()
self.file_location.insert(0, 'C:\Temp\ETHresults.txt')
def graytextbox(self):
if self.make_txt == True:
self.file_location.config(state=DISABLED)
# I've also tried self.file_location.state(['DISABLED'])
else:
self.file_location.config(state=NORMAL)
# I've also tried self.file_location.state(['NORMAL'])
Not only does the code not control the normal/disabled function of the button, but I get AttributeError: instance has no attribute 'file_location'