Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter checkbutton.select() not working on Checkbutton (Python 3)

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?

like image 533
user3315473 Avatar asked May 23 '26 20:05

user3315473


1 Answers

Can you set the value of the boolean instead?

should_auto.set(True)

should update the checkbox that relies on it.

like image 102
Holloway Avatar answered May 25 '26 10:05

Holloway



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!