Tkinter单选按钮在列表框中打印上一个结果

2024-09-30 18:28:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Python还比较陌生。我有一个简单的程序,有3个产品,3个牛奶选项和3个大小和一个添加按钮,所有的单选按钮。用户选择产品,大小,牛奶和按下添加。单选按钮具有与它们相关的值,例如,我的卡布奇诺按钮具有value=“cappuccino”,而我的小按钮具有value=“small”。添加后,值被写入数据库,数据库内容被更新到列表框tkinter小部件;因此它看起来像一个命令。你知道吗

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

任何方法来解决这一点,使每个订单是打印它是。可能是存储先前值的变量。请有人提供一个解决方案。你知道吗

下面的代码并不是全部,但它提供了结构的jist。你知道吗

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")

Tags: imageselfpngvalueplacebuttonvariable按钮