【发布时间】:2017-01-18 20:12:37
【问题描述】:
我将checkbutton 放在text 小部件上,但每次选择checkbutton 时,都会调用函数checkbutton_value,并返回0。
部分代码为:
def callback():
file_name=askopenfilename()
column_1rowname,column_name=draw_column(file_name)
root = Tk()
root.resizable(width=False,height=False)
root.wm_title("Column")
S = Scrollbar(root,orient="vertical")
text=Text(root,width=15,height=10,yscrollcommand=S.set)
S.config(command=text.yview)
S.pack(side="right",fill="y")
text.pack(side="left",fill="both",expand=True)
#check the value of the checkbutton
def checkbutton_value():
if(var.get()):
print 1
else:
print 0
var=BooleanVar()
chk = Checkbutton(root, text=column_1rowname[1], variable=var, command=checkbutton_value)
text.window_create("end", window=chk)
text.config(state=DISABLED)
errmsg='Error!'
Button(text='File Open',command=callback).pack(fill=X)
mainloop()
【问题讨论】:
-
谢谢。我已经改了。
-
这真的是你的真实代码吗?在回调中创建
Tk的实例肯定是个问题。 -
是的。我的代码可以运行。但是当我选择复选按钮时它总是返回 0。