Hi-im正在尝试在python上编写一段代码,根据选中的checkbutton的数量列出标签中的值。为什么我的代码不能工作?在
var1=IntVar()
var2=IntVar()
var3=IntVar()
inlabel = StringVar()
label = Label (the_window, height = 1,bg = "white",width = 30, textvariable = inlabel,font = ("arial",50,"normal")).pack()
def check():
if(var1 == 0 and var2 == 0 and var3==1):
inlabel.set("odd")
if(var1 == 0 and var2 == 1 and var3==1):
inlabel.set("even")
if(var1 == 1 and var2 == 1 and var3==1):
inlabel.set("odd")
if(var1 == 0 and var2 == 1 and var3==0):
inlabel.set("odd")
if(var1 == 1 and var2 == 1 and var3==0):
inlabel.set("even")
if(var1 == 0 and var2 == 0 and var3==0):
inlabel.set("null")
if(var1 == 1 and var2 == 0 and var3==0):
inlabel.set("odd")
if(var1 == 1 and var2 == 0 and var3==1):
inlabel.set("even")
check1 = Checkbutton(the_window, text= "Gamma",variable=var1,command=check)
check2 = Checkbutton(the_window, text= "Beta",variable=var2,command=check)
check3 = Checkbutton(the_window, text= "Alpha",variable=var3,command=check)
check1.pack(side=RIGHT)
check2.pack()
check3.pack(side=LEFT)
谢谢:)
你需要使用变量获取(). 下面是Python3.3中的一个工作示例。在
希望能帮上忙!-埃德
您需要使用
get
并将其分配给另一个变量,而不是var1
。 所以这样的事情应该行得通。在我假设您在实际程序中定义了父窗口(
the_window
)。在相关问题 更多 >
编程相关推荐