I have created a IntVar() this.v. When this.v = 1, my elif statement is true, which should not be the case. What have I done wrong? When I print(this.v.get()) the value returned is 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)
The
elifwill always trigger, as a variable cannot be!= 1and!=2at the same time!That is not a "semantic error", but a logical error by the programmer.