1
我創建了一個IntVar()this.v. 當this.v = 1時,我的elif語句是正確的,不應該如此。 我做錯了什麼? 當我打印(this.v.get())返回的值是1。 (進口Tkinter的)如何正確更改Radiobutton的值?
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)
請添加使用的GUI工具包和定義「不工作」你可能要付出更多的他們,使他們的工作... – Olaf
什麼發生的事情是,elif的語句運行時,它不應該是。當我打印「v」的值是1或2時,但elif語句反正運行。我使用tkinter,我將編輯指定 – Shan
應該更新,讓我仔細檢查。 – Shan