【发布时间】:2015-05-17 07:07:19
【问题描述】:
它应该是一个 GUI 披萨订单表格,所以它有更多但我遇到的问题是当它获取一个应该是 OliveSelection 的变量时,它总是在检查时返回 0 而不是 1。
from tkinter import *
myGui=Tk()
myGui.geometry("800x600")
myGui.title("Pete's Pizza Parlour~Order Form")
TOPPING SELECTION
toppings_lbl=Label(myGui,text="Toppings:",font=("Good Times",10),fg="blue").pack()
a=IntVar()
olives_chk=Checkbutton(myGui,text="Olives",variable=a).pack()
b=IntVar()
tomatoes_chk=Checkbutton(myGui,text="Tomatoes",variable=b).pack()
c=IntVar()
pepperoni_chk=Checkbutton(myGui,text="Pepperoni",variable=c).pack()
d=IntVar()
hotPeppers_chk=Checkbutton(myGui,text="Hot Peppers",variable=d).pack()
e=IntVar()
onions_chk=Checkbutton(myGui,text="Onions",variable=e).pack()
f=IntVar()
ham_chk=Checkbutton(myGui,text="Ham",variable=f).pack()
g=IntVar()
sausage_chk=Checkbutton(myGui,text="Sausage",variable=g).pack()
h=IntVar()
greenPeppers_chk=Checkbutton(myGui,text="Green Peppers",variable=h).pack()
olivesSelection=a.get()
tomatoesSelection=b.get()
pepperoniSelection=c.get()
hotPeppersSelection=d.get()
onionsSelection=e.get()
hamSelection=f.get()
sausageSelection=g.get()
greenPeppersSelection=h.get()
olivesSelectionStr="olives"
tomatoesSelectionStr="tomatoes"
pepperoniSelectionStr="pepperoni"
hotPeppersSelectionStr="hot peppers"
onionsSelectionStr="onions"
hamSelectionStr="ham"
sausageSelectionStr="sausage"
greenPeppersSelectionStr="green peppers"
noToppingsStr="no toppings."
def checkToppings():
toppingsList=""
if(olivesSelection==1):
toppingsList=toppingsList+olivesSelectionStr
elif(tomatoesSelection==1):
toppingsList=toppingsList+tomatoesSelectionStr
elif(pepperoniSelection==1):
toppingsList=toppingsList+pepperoniSelectionStr
elif(hotPeppersSelection==1):
toppingsList=toppingsList+hotPeppersSelectionStr
elif(onionsSelection==1):
toppingsList=toppingsList+onionsSelectionStr
elif(hamSelection==1):
toppingsList=toppingsList+hamSelectionStr
elif(sausageSelection==1):
toppingsList=toppingsList+sausageSelectionStr
elif(greenPeppersSelection==1):
toppingsList=toppingsList+greenPeppersSelectionStr
else:
toppingsList=noToppingsStr
橄榄选择总是返回 0 而不是 1 当它应该被选中时
print(olivesSelection)
【问题讨论】: