2015-12-30 48 views
0

我試圖編程一個餐廳菜單,並在客戶選擇後,它會顯示訂單的總數。我的問題是,當我運行代碼時,文本框中有一個{}。我如何刪除它?如何刪除文本框中的{}?

以下是圖像:

enter image description here

這裏是我的全部代碼。請給我一些關於如何改善它的建議。

# 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() 

回答

3

我假設你的輸出{}實際上是()

final = message, "Total:  $", str(float(total)) 

應該

final = message + "Total:  $" + str(float(total)) 

它發生的原因是使用逗號,你創建了三個字符串,而不是一個字符串的元組,以及一個元組的默認表示周圍有括號。

+0

非常感謝你 –

0
final = message, "Total:  $", str(float(total)) 

,而不是使用字符串連接

final = message + "Total:  %s $"%str(float(total)) 
+0

非常感謝你 –