Tkinter RadioButton在列表框中打印先前的结果

时间:2019-07-17 09:24:55

标签: python oop user-interface tkinter

我对Python相当陌生。我有一个简单的程序,其中有3种产品,3种牛奶选项和3种尺寸以及一个添加按钮,都作为单选按钮。用户选择产品,尺寸,牛奶并按添加。单选按钮具有与之关联的值,例如我的卡布奇诺咖啡按钮值为value =“ cappuccino”,而我的小按钮值为value =“ small”。添加后,将值写入数据库,并将数据库内容更新为列表框tkinter小部件;所以看起来像一个命令。

我的问题是,如果我选择某种产品,尺寸和牛奶类型,它将把这些详细信息写入数据库并打印到列表框中,但是如果选择完全不同的顺序,可能会添加它,当我按添加时,将先前的顺序写入数据库几次,然后它将写入正确的顺序。

以任何方式解决此问题,以便按原样打印每个订单。可能是存储先前值的变量。请有人提供解决方案。

下面的代码不是全部,但可以让您大致了解该结构。

def view_command():
     self.orderList.delete(0,END) #listbox on screen 2
     for row in backend.view():
         self.orderList.insert(END,row)


def addItem():
    view_command()
    choice = v.get()
    size = s.get()
    milkOptions = m.get()

    backend.customerOrders(choice,size,milkOptions)

self.orderList = tk.Listbox(self,width=112)
self.orderList.place(x=0,y=680)
#Scrollbar for Order Listbox
self.scrollbar = tk.Scrollbar(self)
self.scrollbar.place(x=700,y=685)
#Scroll bar to list box configure
self.orderList.config(yscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.orderList.yview)



#Americano Button
self.americanoImage = tk.PhotoImage(file="ResizedItemImages/HotDrinks/americanoResized.png")
#self.americanoButton = tk.Radiobutton(self,image=self.americanoImage, command=lambda: product("Americano"),variable=v)
self.americanoButton = tk.Radiobutton(self,image=self.americanoImage,variable=v, value="Americano")

#Cappucino Button
self.cappucinoImage = tk.PhotoImage(file="ResizedItemImages/HotDrinks/cappucinoResized.png")
#self.cappucinoButton = tk.Radiobutton(self,image=self.cappucinoImage, command=lambda: product("Cappucino"),variable=v)
self.cappucinoButton = tk.Radiobutton(self,image=self.cappucinoImage,variable=v, value="Cappucino")

#Espresso Button
self.espressoImage = tk.PhotoImage(file="ResizedItemImages/HotDrinks/espressoResized.png")
#self.espressoButton = tk.Radiobutton(self,image=self.espressoImage, command=lambda: product("Cappucino"),variable=v)
 self.espressoButton = tk.Radiobutton(self,image=self.espressoImage,variable=v, value="Espresso")

#Add button
self.addImage = PhotoImage(file="ResizedItemImages/Function/addResized.png")
self.addButton = Button(self,image=self.addImage,command=addItem)
self.addButton.place(y=550,x=440)

#Small button
self.smallImage = tk.PhotoImage(file="ResizedItemImages/Function/smallResized.png")
self.smallButton = tk.Radiobutton(self,image=self.smallImage,
                                     variable=s, value="Small")
self.smallButton.place(y=550,x=0)
#Medium Button
self.mediumImage = tk.PhotoImage(file="ResizedItemImages/Function/medium_Resized.png")
 self.mediumButton = tk.Radiobutton(self,image=self.mediumImage,
                                      variable=s, value="Medium")
self.mediumButton.place(y=550,x=140)
#Large button
self.largeImage = tk.PhotoImage(file="ResizedItemImages/Function/largeResized.png")
self.largeButton = tk.Radiobutton(self,image=self.largeImage,
                                     variable=s, value="Large")
self.largeButton.place(y=550,x=290)

#ALL MILK OPTION BUTTONS
#Soya Milk Button
self.soyaMilkImage = tk.PhotoImage(file="ResizedItemImages/MilkOptions/soyaMilkResized.png")
self.soyaMilkButton = tk.Radiobutton(self, image=self.soyaMilkImage,variable=m, value="Soya")
#Cocounut Milk Button
self.coconutMilkImage = tk.PhotoImage(file="ResizedItemImages/MilkOptions/coconutMilkResized.png")
self.coconutMilkButton = tk.Radiobutton(self, image=self.coconutMilkImage,variable=m, value="Coconut")
#Whole Milk
self.wholeMilkImage = tk.PhotoImage(file="ResizedItemImages/MilkOptions/wholeMilkResized.png")
self.wholeMilkButton = tk.Radiobutton(self, image=self.wholeMilkImage,variable=m, value="Whole")

0 个答案:

没有答案