2014-03-05 88 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