大家好,我是相对较不熟悉编程的人,但都是试图使用GUI界面来构建小费计算器的人。没有什么大的,没有什么相对困难的,但是我遇到了错误。由于某种原因,我的Python不会显示错误。语法错误:它只是进入 shell ,然后返回脚本。它曾经显示错误,但我不知道怎么了...无论如何,如果你们可以帮助我解决此ID问题,我们将不胜感激。
`
# A tip calculator
# A tip calculator using a GUI interface
# Austin Howard Aug - 13 - 2014
from tkinter import *
#Creating buttons.
class Calculator(Frame):
""" A GUI tip calculator."""
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.creating_buttons()
def creating_buttons(self):
"""This list includes Entry fields, which the user will use to define
several objects such as Bill, and how many people are paying on that bill."""
#Create an entry field button for how much the bill total is.
#Create a label
bill_lbl = Label(self,
text = "Bill: ")
bill_lbl.grid(row = 1,
column = 0,
columnspan = 1,
sticky = W)
#Create an Entry field.
bill_ent = Entry(self)
bill_ent.grid(row = 1,
column = 1,
sticky = W)
#Create a Button for how many people will be paying on the bill
#Create label
people_paying_lbl = Label(self,
text = "How many people are paying on this bill?: ")
people_paying_lbl.grid(row = 2,
column = 0,
columnspan = 1,
sticky = W)
#Create an entry field
people_paying_ent = Entry(self)
people_paying_ent.grid(row = 2,
column = 1,
sticky = W)
#Create a text box to display the totals in
bill_total_txt = Text(self,
width = 40,
height = 40,
wrap = WORD)
bill_total_txt.grid(row = 3,
column = 0,
columnspan = 2,
sticky = W)
#Create a Submit button
submit = Button(self,
text = "Submit",
command = self.total)
submit.grid(row = 4,
column = 0,
sticky = W)
def total(self):
""" Takes the values from Bill, and # of people to get the amount that will be
displayed in the text box."""
TAX = .15
bill = float(bill_ent)
people = people_paying_ent
Total = ("The tip is: $", TAX * bill, "\nThe total for the bill is: $",
TAX * bill + bill,
"divided among the people paying equally is: $",
TAX * bill + bill / people "per, person.")
bill_total_txt.delete(0.0, END)
bill_total_txt.insert(0.0, Total)
#Starting the Program
root = Tk()
root.title("Tip Calculator")
app = Calculator(root)
root.mainloop()
`
最佳答案
您在第68行有一个错误:
更换
TAX * bill + bill / people "per, person.")
与
TAX * bill + bill / people, "per, person.")
还要确保在
root.mainloop()
之后删除反引号
关于python - 提示计算器-语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25299828/