2014-03-05 167 views
1

我正在写一个程序,它从一个文件读取数据,并相应地调整设置。这是我创建的checkbutton:Tkinter checkbutton.select()不工作Checkbutton(Python 3)

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) 

然后我尝试 “检查”,它使用:

autodetect.select() 

但这返回以下错误:

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' 

我已经还试图使用autodetect.set(True),但后来我得到几乎相同的错误,但Checkbutton object has no attribute 'set'我看到了effcot.org上的.select(),但也许这不是python 3?

+0

使用'autodetect.set(1)'? – Gogo

+0

仍然会得到相同的错误。 – user3315473

回答

0

你可以设置布尔值的值吗?

should_auto.set(True) 

应更新依赖它的复选框。

+0

是的,它会做到这一点..你打我吧;) – Gogo

+0

autodtect.set(1)可能已经工作,但那是按钮,而不是变量。无论如何,谢谢你们。 – user3315473