如何删除文本框中的{}?
问题描述:
我试图编程一个餐厅菜单,并在客户选择后,它会显示订单的总数。我的问题是,当我运行代码时,文本框中有一个{}
。我如何删除它?如何删除文本框中的{}?
以下是图像:
这里是我的全部代码。请给我一些关于如何改善它的建议。
# Restaurant Menu
from tkinter import *
class Application(Frame):
def __init__(self, master):
super(Application, self).__init__(master)
self.grid()
self.create_widgets()
def create_widgets(self):
Label(self,
text="Menu",
).grid(row=0, column= 0, sticky= W)
Label(self,
text="Choose your orders and click to submit to know the total price to pay."
).grid(row=1, column= 0, columnspan = 3, sticky=W)
Label(self,
text= "Meal:"
).grid(row=2, column=0, sticky=W)
self.chicken = BooleanVar()
Checkbutton(self,
text= "Fried Chicken.................$30",
variable=self.chicken
).grid(row=3, column = 0, sticky =W)
self.baboy=BooleanVar()
Checkbutton(self,
text="Lechon Pig....................$25",
variable=self.baboy
).grid(row=4, column=0, sticky=W)
self.pancit=BooleanVar()
Checkbutton(self,
text="Pancit Guisado................$10",
variable=self.pancit
).grid(row=5,column=0, sticky=W)
self.beef_ribs=BooleanVar()
Checkbutton(self,
text= "Beef Ribs....................$20",
variable=self.beef_ribs
).grid(row=6, column=0, sticky=W)
self.fish = BooleanVar()
Checkbutton(self,
text="Fish Fellet...................$15",
variable=self.fish
).grid(row=7, column=0, sticky=W)
Label(self,
text="Drinks:"
).grid(row=2, column=1, sticky=W)
self.coke=BooleanVar()
Checkbutton(self,
text="Coke..........................$2.75",
variable=self.coke
).grid(row=3, column=1, sticky =W)
self.pineapple=BooleanVar()
Checkbutton(self,
text="Pineapple Juice...............$2",
variable=self.pineapple
).grid(row=4, column=1, sticky =W)
self.orange = BooleanVar()
Checkbutton(self,
text="Orangeg Juice.................$1.75",
variable=self.orange
).grid(row=5, column= 1, sticky=W)
self.water=BooleanVar()
Checkbutton(self,
text="Water.........................$1",
variable=self.water
).grid(row=6, column=1, sticky=W)
Button(self,
text="Submit Order",
command=self.total
).grid(row=8, column= 0, sticky=W)
self.total_box = Text(self, width = 75, height =10, wrap =WORD)
self.total_box.grid(row=9, column=0, columnspan = 3, sticky=W)
def total(self):
total = 0
message = ""
if self.chicken.get():
message += "\nChicken ----> $30.00\n"
total += 30
if self.baboy.get():
message += "Baboy ------> $25.00\n"
total += 25
if self.pancit.get():
message += "Pancit -----> $10.00\n"
total += 10
if self.beef_ribs.get():
message += "Beef Ribs --> $20.00\n"
total += 20
if self.fish.get():
message += "Fish -------> $15.00\n"
total += 15
if self.coke.get():
message += "Coke -------> $2.75\n"
total += 2.75
if self.pineapple.get():
message += "Pineapple --> $2.00\n"
total += 2
if self.orange.get():
message += "Orange -----> $1.75\n"
total += 1.75
if self.water.get():
message += "Water ------> $1.00\n"
total += 1
final = message, "Total: $", str(float(total))
self.total_box.delete(0.0, END)
self.total_box.insert(0.0, final)
root = Tk()
root.title("Restaurant Menu and Total Cost of Order.")
app = Application(root)
root.mainloop()
答
我假设你的输出{}
实际上是()
。
final = message, "Total: $", str(float(total))
应该
final = message + "Total: $" + str(float(total))
它发生的原因是使用逗号,你创建了三个字符串,而不是一个字符串的元组,以及一个元组的默认表示周围有括号。
答
final = message, "Total: $", str(float(total))
,而不是使用字符串连接
final = message + "Total: %s $"%str(float(total))
+0
非常感谢你 –
非常感谢你 –