4

I am writing a program which reads data form a file, and adjust the settings accordingly. This is how I created the checkbutton:

should_auto = BooleanVar()    
autodetect = Checkbutton(root, text="Autodetect", var=should_auto, onvalue = True, offvalue = False, command=toggle_delay)
autodetect.grid(row=0, column=2, padx=7, pady=5, sticky=W)

I then try to "check" it using:

autodetect.select()

but this returns following error:

Traceback (most recent call last):
  File "C:\Users\CedBook\Documents\GitHub\live-image-desktop-background\src\GUI.py", line 110, in <module>
    autodetect.select()
AttributeError: 'Checkbutton' object has no attribute 'select'

I have already also tried using autodetect.set(True), but then i get almost the same error, but Checkbutton object has no attribute 'set' I saw .select() on effbot.org, but maybe that is not for python 3?

user3315473
  • 183
  • 2
  • 7

1 Answers1

1

Can you set the value of the boolean instead?

should_auto.set(True)

should update the checkbox that relies on it.

Holloway
  • 6,412
  • 1
  • 26
  • 33
  • yup that would do it..you beat me to it ;) – Alok Mar 05 '14 at 10:05
  • autodtect.set(1) might have worked, but that was the button, not the variable. Thanks anyway both of you. – user3315473 Mar 05 '14 at 10:43
  • AttributeError: 'Checkbutton' object has no attribute 'set' – Ath.Bar. May 29 '21 at 07:52
  • @Ath.Bar. it sounds like you're trying to set the value of the checkbutton not the variable backing it, See the OP where `should_auto` is a `BooleanVar` and is passed to the `Checkbutton` as the `var` keyword. – Holloway May 30 '21 at 20:36