简体   繁体   中英

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?

Can you set the value of the boolean instead?

should_auto.set(True)

should update the checkbox that relies on it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM