AndrewSwanson94 AndrewSwanson94 - 17 days ago 7
Python Question

Python GUI Graphics Calculator

I am trying to make a store calculator from the graphics library and my program keeps crashing due to unknown reasons. Just whenever I click the calculate button, it stops running and I get no output. Here is what I have as of now:

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

Answer

setText() is not print(), it needs one argument

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