【发布时间】:2013-11-22 14:31:25
【问题描述】:
我已经尝试了几个examples from stackoverflow,但不幸的是没有为我工作。
我只想获取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 被选中时是否可以获取它们的值。还有我应该在哪个属性上寻找这个?
【问题讨论】:
标签: python python-2.7 tkinter