2016-11-17 81 views
-1

我想从图形库中制作商店计算器,并且由于未知原因我的程序不断崩溃。只要我点击计算按钮,它就会停止运行,并且我没有输出。下面是我到现在为止:Python GUI图形计算器

# graphical interface. 
from graphics import * 
def main(): 
win = GraphWin("Celsius Converter", 600, 500) 
win.setCoords(0.0, 0.0, 3.0, 4.0) 

# Draw the interface 
Text(Point(1,3.9), " Enter name:").draw(win) 
Text(Point(1,3.7), " Crunchy tacos at $1.99 each:").draw(win) 
Text(Point(1,3.5), " Soft tacos at $2.09 each:").draw(win) 
Text(Point(1,3.3), " Bean burritos at $2.49 each:").draw(win) 
Text(Point(1,3.1), " Chicken burritos at $2.99 each:").draw(win) 
Text(Point(1,2.9), " Taco salads at $3.49 each:").draw(win) 
Text(Point(1,2.7), " Extra salsa at $.30 each:").draw(win) 
Text(Point(1,1), "Due:").draw(win) 
input1 = Entry(Point(2,3.9), 5) 
input1.setText("Name") 
input1.draw(win) 
input2 = Entry(Point(2,3.7), 5) 
input2.setText("0") 
input2.draw(win) 
input3 = Entry(Point(2,3.5), 5) 
input3.setText("0") 
input3.draw(win) 
input4 = Entry(Point(2,3.3), 5) 
input4.setText("0") 
input4.draw(win) 
input5 = Entry(Point(2,3.1), 5) 
input5.setText("0") 
input5.draw(win) 
input6 = Entry(Point(2,2.9), 5) 
input6.setText("0") 
input6.draw(win) 
input7 = Entry(Point(2,2.7), 5) 
input7.setText("0") 
input7.draw(win) 
output = Text(Point(2,1),"") 
output.draw(win) 
button = Text(Point(1.5,2.0),"Calculate") 
button.draw(win) 
Rectangle(Point(1,1.5), Point(2,2.5)).draw(win) 
# wait for a mouse click 
win.getMouse() 

# convert input 
name = input1.getText() 
crunchy = float(input2.getText()) * 1.99 
soft = float(input3.getText()) * 2.09 
bean = float(input4.getText()) * 2.49 
chicken = float(input5.getText()) * 2.99 
salad = float(input6.getText()) * 3.49 
salsa = float(input7.getText()) * 0.30 
costBefore = (crunchy + soft + bean + chicken + salad + salsa) 
tax = 0.075 * costBefore 
cost = costBefore + tax 

# display output and change button 
output.setText("Hello", name, ",your total is: ", cost) 
button.setText("Quit") 

# wait for click and then quit 
win.getMouse() 
win.close() 

main() 
+1

尝试从你的代码中获得一个最小的,但完整和可核查的例子。这将帮助我们,帮助你找到你的错误,*如果*你没有在它的过程中发现你自己(通常有很高的可能性)。在此处查找有关此主题的更多信息:http://stackoverflow.com/help/mcve – derM

+0

是否发生错误?你有错误信息可以放在这里吗? –

+0

根据您使用的IDE,您可能也有可能使用出色的调试器。尝试在关键位置设置一些断点,并检查,如果你到达他们,以及你的程序有什么状态。 – derM

回答

1

setText()print(),它需要一个参数

output.setText("Hello {}, your total is: {}".format(name, cost))