我正在为我餐厅的员工进行菜单测试。该计划是让菜单项在“此处循环项目”中循环,此时他们选择正确的复选按钮(成分),然后单击“提交并继续按钮”。当他们单击提交按钮时,我首先需要读取检查按钮的打开和关闭值以确定他们选择了哪些项目,然后将这些与我在列表字典中定义的正确答案进行比较,然后清除所有检查按钮以及是否答案是错误的还是正确的,程序将继续运行,我最终会有一个结果屏幕,但现在我被困在如何读取检查按钮的开和关值上。我现在只是想打印选定的蔬菜,但无法弄清楚。
我认为这与它们采用不同的方法以及它们是在循环中添加的事实有关吗?我不确定,但我知道我的代码试图读取错误的内容,任何帮助将不胜感激!
很抱歉这个冗长的问题,我只是认为向您提供尽可能多的信息以了解我正在尝试做的事情是有益的..
from tkinter import *
class GUI(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.grid()
self.parent.title("Wahoos Menu Test")
self.create_buttons()
global count
count = -1
def create_buttons(self):
for r in range(20):
for c in range(14):
Label(self, text='',
borderwidth=0).grid(row=r,column=c)
B = Button(self, text ="Begin Exam", relief=RIDGE, fg="black", command= self.on_button_press).grid(row=19, column=7)
L = Label(self, text="What comes in the following", fg="blue").grid(row=6, column=0)
self.veg = ['Lettuce', 'Cabbage', 'Cheese', 'Ahee Rice', 'Brown Rice', 'Banzai Veg', 'Red Cabbage', 'Black Beans', 'Cajun White Beans']
self.vegboxes = []
self.opt = []
c = 1
for ve in self.veg:
c +=1
self.v = IntVar()
self.vegboxes.append(self.v)
vo = Checkbutton(self, text=ve, variable=self.v, onvalue=1, offvalue=0).grid(row=c, column=11, sticky=W)
def on_button_press(self):
global count
count = count + 1
menuItems = {'nft': ['cabbage', 'cheese', 'corn', 'nf', 'salsa'],
'nckt': ['lettuce', 'cheese', 'corn', 'nck', 'salsa']}
menu = ['blackened fish taco', 'wahoos chicken salad']
if count == len(menu):
C = Button(self, text =" Your Done! ", relief=RIDGE, fg="black").grid(row=19, column=7)
else:
m = Label(self, text=menu[count], fg="black").grid(row=7, column=0)
C = Button(self, text ="Submit and Continue", relief=RIDGE, fg="black", command= self.read_checks).grid(row=19, column=7)
def read_checks(self):
for v in self.veg:
if self.v == 1:
print(self.veg[v])
def main():
root = Tk()
app = GUI(root)
root.mainloop()
if __name__ == '__main__':
main()