如何删除文本框中的{}?

时间:2015-12-30 06:53:20

标签: python tkinter

我正在尝试对餐馆菜单进行编程,在客户选择之后,它将显示订单的总体总数。我的问题是,当我运行代码时,文本框中有一个{}。我该如何删除它?

这是图片:

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

2 个答案:

答案 0 :(得分:3)

我假设您输出中的{}实际上是()

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

应该是

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

它发生的原因是,通过使用逗号,您创建了一个由三个字符串而不是单个字符串组成的元组,并且元组的默认表示在其周围有括号。

答案 1 :(得分:0)

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

而不是使用字符串连接

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