0
我已經嘗試了幾個examples from stackoverflow,但不幸的是我不工作。Tkinter得到一個CheckButton的選定值
我只想得到選定的Tkinter,Python的checkButton的值。
我有CheckButton名單及其類似下面
## csv file has rows like
# 101, apple
# 102, orange
for row in csvReader:
checkButton = Checkbutton(top, text = row[1], variable = StringVar(),
onvalue = row[0], offvalue = "0", height=2, \
width = 0, justify=Tkinter.LEFT)
checkButton.pack()
checkBoxList.append(checkButton)
在從表單點擊一個按鈕,在這裏是需要抓住複選框的選中的值回調。
def btnStartCallBack():
for chkBox in checkBoxList:
print chkBox.variable().get()
# also tried below
# print chkBox.get()
# print chkBox.var()
# print chkBox.onvalue.get()
返回:
AttributeError: Checkbutton instance has no attribute 'variable'
我只是想知道是否有可能或不被選擇時,他們得到CheckButton的價值。而且我應該尋找這個屬性?
是的,你是對的。其也相似。我必須以不同的方式聲明變量。 ** CheckVar1 = StringVar()**和** Checkvar1.get()**返回值。輕鬆...謝謝m8 ... –
沒問題。我記得我第一次知道這些東西 - 我不知道我必須使用'get()',並且花了我數小時才弄明白。 – cjohnson318