-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()
嘗試從你的代碼中獲得一個最小的,但完整和可覈查的例子。這將幫助我們,幫助你找到你的錯誤,*如果*你沒有在它的過程中發現你自己(通常有很高的可能性)。在此處查找有關此主題的更多信息:http://stackoverflow.com/help/mcve – derM
是否發生錯誤?你有錯誤信息可以放在這裏嗎? –
根據您使用的IDE,您可能也有可能使用出色的調試器。嘗試在關鍵位置設置一些斷點,並檢查,如果你到達他們,以及你的程序有什麼狀態。 – derM