Reputation: 127
I'm trying to program a restaurant menu and after a customer's choice, it will display the overall total of the order. My problem is that when I ran the code, there's a {}
in the textbox. How can I delete it?
Here is the image:
Here is my full code. Please do give me some advice on how to improve it.
# 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()
Upvotes: 0
Views: 74
Reputation: 184280
I'm assuming that the {}
in your output is actually ()
.
final = message, "Total: $", str(float(total))
should be
final = message + "Total: $" + str(float(total))
The reason it happened is that by using commas, you created a tuple of three strings rather than a single string, and the default representation of a tuple has parentheses around it.
Upvotes: 3
Reputation: 149
final = message, "Total: $", str(float(total))
instead of use string concatenation
final = message + "Total: %s $"%str(float(total))
Upvotes: 0