我创建了一个IntVar()this.v. 当this.v = 1时,我的elif语句是真的,不应该是这种情况。 我做错了什么? 当我打印(this.v.get())时返回的值是1。 (import tkinter)
this.v = IntVar()
this.button1 = Radiobutton(this.root,text = "Small Boxes First",variable = this.v,value = 1)
this.button1.grid(row = 2,column = 5)
this.button2 = Radiobutton(this.root,text = "Large Boxes First",variable = this.v,value = 2)
this.button2.grid(row = 3,column = 5)
def packNSaveClicked(this):
if(int(this.wid.get()) <= 0 or int(this.len.get()) <= 0 or this.len.get() == '' or this.wid.get() == ''):
messagebox.showerror("Truck Size Error", "The length or width of the Truck is not a valid value!")
elif(int(this.v.get()) != 1 or int(this.v.get()) != 2):
#ALWAYS SHOWING UP, even though print statement prints out 1 or 2
print(this.v.get())
messagebox.showerror("Packing Error", "Pack algorithm not selected!")
else:
...(this code not relevant)
答案 0 :(得分:1)
elif
将始终触发,因为变量不能同时为!= 1
和 !=2
!
这不是&#34;语义错误&#34;,而是程序员的逻辑错误。
答案 1 :(得分:0)
当你说'#34;如果x不是1那么这样做,或者如果x不是2&#34;则执行此操作,它将始终运行。请考虑以下值: