Python 2.7 Python错误弹出窗口不工作
写代码时,我不知怎的把它弄坏了,记不起以前的工作是什么,只使用了几周的python,在完成了一整天的工作之后,我有点沮丧Python 2.7 Python错误弹出窗口不工作,python-2.7,exception,try-except,Python 2.7,Exception,Try Except,写代码时,我不知怎的把它弄坏了,记不起以前的工作是什么,只使用了几周的python,在完成了一整天的工作之后,我有点沮丧 # A program to calculate delivery order totals from graphics import * #Error Window def errorWindow(): errwin = GraphWin("Error", 200, 200) errwin.setCoords(0.0, 0.0, 4.0, 4.0) errwin.set
# A program to calculate delivery order totals
from graphics import *
#Error Window
def errorWindow():
errwin = GraphWin("Error", 200, 200)
errwin.setCoords(0.0, 0.0, 4.0, 4.0)
errwin.setBackground(color_rgb(33,158,87))
Text(Point(2, 3), "This is not a valid order").draw(errwin)
Text(Point(2, 2.5), "Please try again").draw(errwin)
outline = Rectangle(Point(1.5,1), Point(2.5,2))
outline.setFill('white')
outline.draw(errwin)
okbutton = Text(Point(2,1.5),"OK")
okbutton.draw(errwin)
done=errwin.getMouse()
if (done.getX() > 1.5 and done.getX() < 2.5):
errwin.close()
def main():
win = GraphWin("Brandi's Bagel House", 500, 500)
win.setCoords(0.0, 0.0, 10.0, 10.0)
win.setBackground(color_rgb(33,158,87))
#Banner
banner = Rectangle(Point(0, 8), Point(10, 10))
banner.setFill(color_rgb(97,76,26))
banner.setOutline(color_rgb(97,76,26))
banner.draw(win)
#Logo Image
circ = Circle(Point(1,9), .65)
circ.setFill('white')
circ.setOutline('white')
circ.draw(win)
circ2 = Circle(Point(1,9), .6)
circ2.setFill(color_rgb(33,158,87))
circ2.setOutline(color_rgb(33,158,87))
circ2.draw(win)
bigb = Text(Point(1, 9),"B")
bigb.setStyle('bold italic')
bigb.setTextColor('white')
bigb.setFace('courier')
bigb.setSize(28)
bigb.draw(win)
#Horizontal Lines
Line(Point(0,2.25), Point(10,2.25)).draw(win)
Line(Point(0,4.25), Point(10,4.25)).draw(win)
Line(Point(0,6.25), Point(10,6.25)).draw(win)
#Text
title = Text(Point(4,9), "Delivery Orders:")
title.setSize(20)
title.setTextColor('white')
title.draw(win)
Text(Point(1.5,7), "Bagels:").draw(win)
whitetext = Text(Point(3,7.5), "White")
whitetext.setSize(10)
whitetext.draw(win)
wheattext = Text(Point(5,7.5), "Wheat")
wheattext.setSize(10)
wheattext.draw(win)
Text(Point(1.5,5), "Toppings:").draw(win)
creamtext = Text(Point(3,5.8), "Cream")
creamtext.setSize(10)
creamtext.draw(win)
cheesetext = Text(Point(3,5.5), "Cheese")
cheesetext.setSize(10)
cheesetext.draw(win)
buttertext = Text(Point(5,5.5), "Butter")
buttertext.setSize(10)
buttertext.draw(win)
jellytext = Text(Point(7,5.5), "Jelly")
jellytext.setSize(10)
jellytext.draw(win)
Text(Point(1.5,3), "Coffee:").draw(win)
regtext = Text(Point(3,3.5), "Regular")
regtext.setSize(10)
regtext.draw(win)
decaftext = Text(Point(5,3.5), "Decaf")
decaftext.setSize(10)
decaftext.draw(win)
Text(Point(7,1.5), "Subtotal:").draw(win)
Text(Point(7,1), "Tax:").draw(win)
Text(Point(7,0.5), "Total:").draw(win)
#input bagel
bagel1 = Entry(Point(3,7), 3)
bagel1.setText("0")
bagel1.draw(win)
bagel2 = Entry(Point(5,7), 3)
bagel2.setText("0")
bagel2.draw(win)
#input topping
top1 = Entry(Point(3,5), 3)
top1.setText("0")
top1.draw(win)
top2 = Entry(Point(5,5), 3)
top2.setText("0")
top2.draw(win)
top3 = Entry(Point(7,5), 3)
top3.setText("0")
top3.draw(win)
#input coffee
coff1 = Entry(Point(3,3), 3)
coff1.setText("0")
coff1.draw(win)
coff2 = Entry(Point(5,3), 3)
coff2.setText("0")
coff2.draw(win)
#Calculate Button
outer1 = Rectangle(Point(4.2,0.6), Point(5.8,1.4))
outer1.setFill('white')
outer1.draw(win)
button = Text(Point(5,1),"Calculate")
button.draw(win)
#Quit Buttons
outer2 = Rectangle(Point(9,9.2), Point(9.95,9.95))
outer2.setFill('white')
outer2.draw(win)
button = Text(Point(9.5,9.6),"Quit")
button.draw(win)
#Output
subtotaloutput = Text(Point(9,1.5), "$0.00")
subtotaloutput.draw(win)
taxoutput = Text(Point(9,1), "$0.00")
taxoutput.draw(win)
totaloutput = Text(Point(9,0.5), "$0.00")
totaloutput.draw(win)
#calculations
whitebagel = eval(bagel1.getText())
whitetotal = whitebagel* 1.25
wheatbagel = eval(bagel2.getText())
wheattotal = wheatbagel*1.50
creamcheese = eval(top1.getText())
creamtotal = creamcheese* 0.50
butter = eval(top2.getText())
buttertotal = butter*0.25
jelly = eval(top3.getText())
jellytotal = jelly*0.75
regularcoff = eval(coff1.getText())
regulartotal = regularcoff*1.25
decafcoff = eval(coff2.getText())
decaftotal = decafcoff*1.25
click = win.getMouse()
if (click.getX() > 4.2 and click.getX() < 5.8 and (whitebagel >0 or wheatbagel >0)):
subtotal = whitetotal+wheattotal+creamtotal+buttertotal+jellytotal+regulartotal+decaftotal
tax = .06
taxes = subtotal*tax
total = taxes+subtotal
subtotal = "$%0.2f" % (subtotal)
taxes = "$%0.2f" % (taxes)
total = "$%0.2f" % (total)
subtotaloutput.setText(subtotal)
taxoutput.setText(taxes)
totaloutput.setText(total)
#Coffee Cup Image
bottomoval = Oval(Point(0.7,0.4), Point(1.4, 0.7))
bottomoval.setFill(color_rgb(97,76,26))
bottomoval.setOutline(color_rgb(97,76,26))
bottomoval.draw(win)
cup = Rectangle(Point(0.7,0.5), Point(1.4,1.3))
cup.setFill(color_rgb(97,76,26))
cup.setOutline(color_rgb(97,76,26))
cup.draw(win)
topoval = Oval(Point(0.6,1.2), Point(1.5, 1.5))
topoval.setFill('white')
topoval.setOutline(color_rgb(97,76,26))
topoval.draw(win)
coffee = Oval(Point(0.7,1.26), Point(1.4, 1.45))
coffee.setFill(color_rgb(71,54,14))
coffee.setOutline(color_rgb(71,54,14))
coffee.draw(win)
tinycirc = Circle(Point(1.05,0.8), .3)
tinycirc.setFill(color_rgb(33,158,87))
tinycirc.setOutline('white')
tinycirc.draw(win)
letter = Text(Point(1.05,0.8),"B")
letter.setStyle('bold italic')
letter.setTextColor('white')
letter.setFace('courier')
letter.setSize(17)
letter.draw(win)
#Bagel
outerbagel = Oval(Point(1.8, 0.4), Point(2.7, 1))
outerbagel.setFill(color_rgb(191,157,61))
outerbagel.draw(win)
shadow = Oval(Point(2.1, 0.7), Point(2.4, 0.8))
shadow.setFill(color_rgb(130,102,26))
shadow.draw(win)
elif(click.getX() > 4.2 and click.getX() < 5.8 and whitebagel <1 and wheatbagel <1):
errorWindow()
#End
point = win.getMouse()
if (point.getX() > 9 and point.getX() < 9.95):
win.close()
main()
#计算交货订单总数的程序
从图形导入*
#错误窗口
def errorWindow():
errwin=GraphWin(“错误”,200200)
errwin.setCoords(0.0,0.0,4.0,4.0)
errwin.挫折背景(颜色_rgb(33158,87))
文本(第(2,3)点,“这不是有效订单”)。绘图(errwin)
文本(第(2,2.5)点,“请再试一次”)。绘图(errwin)
轮廓=矩形(点(1.5,1),点(2.5,2))
outline.setFill('白色')
轮廓绘制(errwin)
OK按钮=文本(点(2,1.5),“OK”)
确定按钮。绘制(errwin)
done=errwin.getMouse()
如果(done.getX()>1.5和done.getX()<2.5):
errwin.close()
def main():
win=GraphWin(“布兰迪百吉饼屋”,500500)
win.setCoords(0.0,0.0,10.0,10.0)
胜利。挫折(颜色_rgb(33158,87))
#横幅
横幅=矩形(点(0,8),点(10,10))
横幅.设置填充(颜色_rgb(97,76,26))
横幅.背景轮廓(颜色_rgb(97,76,26))
横幅。平局(赢)
#标志图像
circ=圆(点(1,9),.65)
循环设置填充(“白色”)
大概设置轮廓(“白色”)
保监抽签(赢)
圆2=圆(点(1,9),.6)
约2.设置填充(颜色_rgb(33158,87))
约2.setOutline(彩色rgb(33158,87))
大约2.平局(赢)
bigb=文本(第(1,9)点,“B”)
bigb.setStyle('粗体斜体')
bigb.setTextColor('白色')
bigb.setFace('courier')
bigb.setSize(28)
大B.平局(赢)
#水平线
线(点(0,2.25),点(10,2.25))。平局(赢)
线(点(0,4.25),点(10,4.25))。平局(赢)
线(点(0,6.25),点(10,6.25))。平局(赢)
#正文
标题=文本(第(4,9)点,“交货单:”)
标题.设置大小(20)
title.setTextColor('白色')
冠军。平局(胜利)
文本(第(1.5,7)点,“百吉饼:”)。平局(赢)
白色文本=文本(第(3,7.5)点,“白色”)
设置大小(10)
whitetext.draw(赢)
wheattext=文本(第(5,7.5)点,“小麦”)
wheattext.设置大小(10)
wheattext.平局(赢)
文字(第(1.5,5)点,“浇头:)。平局(赢)
奶油文本=文本(第(3,5.8)点,“奶油”)
creamtext.setSize(10)
抽签(赢)
奶酪文本=文本(第(3,5.5)点,“奶酪”)
cheesetext.setSize(10)
cheesetext.draw(赢)
buttertext=文本(第(5,5.5)点,“黄油”)
buttertext.setSize(10)
buttertext.draw(赢)
果冻文本=文本(第(7,5.5)点,“果冻”)
设置文本大小(10)
draw(赢)
文本(第(1.5,3)点,“咖啡:”)。平局(赢)
regtext=文本(第(3,3.5)点,“常规”)
regtext.setSize(10)
regtext.draw(win)
decaftext=文本(第(5,3.5)点,“Decaf”)
decaftext.setSize(10)
decaftext.draw(赢)
文本(第(7,1.5)点,“小计:)。平局(赢)
文本(第(7,1)点,“税:)。抽签(赢)
文字(分数(7,0.5),“总计:)。平局(获胜)
#输入百吉饼
bagel1=入口(点(3,7),3)
bagel1.setText(“0”)
百吉饼1.平局(赢)
bagel2=入口(点(5,7),3)
bagel2.setText(“0”)
面包圈2.平局(赢)
#输入打顶
top1=入口(点(3,5),3)
top1.setText(“0”)
top1.平局(获胜)
top2=入口(点(5,5),3)
top2.setText(“0”)
top2.平局(获胜)
top3=入口(点(7,5),3)
top3.setText(“0”)
top3.平局(胜利)
#输入咖啡
coff1=入口(点(3,3),3)
coff1.setText(“0”)
coff1.平局(赢)
coff2=入口(点(5,3),3)
coff2.setText(“0”)
coff2.平局(赢)
#计算按钮
outer1=矩形(点(4.2,0.6),点(5.8,1.4))
outer1.setFill('白色')
1.抽签(赢)
按钮=文本(点(5,1),“计算”)
按钮。抽签(赢)
#退出按钮
outer2=矩形(点(9,9.2),点(9.95,9.95))
outer2.setFill('白色')
外线2.平局(赢)
按钮=文本(第(9.5,9.6)点,“退出”)
按钮。抽签(赢)
#输出
小计输出=文本(第(9,1.5点),“$0.00”)
小计输出。绘制(win)
taxoutput=文本(第(9,1)点),“$0.00”)
taxoutput.draw(win)
总输出=文本(点(9,0.5),“$0.00”)
totaloutput.draw(赢)
#计算
whitebagel=eval(bagel1.getText())
whitetotal=whitebagel*1.25
wheatbagel=eval(bagel2.getText())
wheattotal=麦面包圈*1.50
creamcheese=eval(top1.getText())
奶油总数=奶油干酪*0.50
butter=eval(top2.getText())
黄油总量=黄油*0.25
jelly=eval(top3.getText())
果冻总量=果冻*0.75
regularcoff=eval(coff1.getText())
regulartotal=regularcoff*1.25
decafcoff=eval(coff2.getText())
decaftotal=decafcoff*1.25
click=win.getMouse()
如果(单击.getX()>4.2并单击.getX()<5.8和(白面包圈>0或麦面包圈>0)):
小计=whitetotal+WheaTotal+creamtotal+buttertotal+jellytotal+regulartotal+Decaptotal
税款=.06
税金=小计*税金
总计=税金+小计
小计=“$%0.2f”%(小计)
税款=“$%0.2f”%(税款)
total=“$%0.2f”%(总计)
小计输出.setText(小计)
taxoutput.setText(税)
totaloutput.setText(总计)
#咖啡杯图像
底部椭圆=椭圆(点(0.7,0.4),点(1.4,0.7))
底部椭圆形。设置填充(颜色_rgb(97,76,26))
底部椭圆形轮廓(颜色为rgb(97,76,26))
平局(赢)
杯形=矩形(点(0.7,0.5),点(1.4,1.3))
杯形填充物(颜色_rgb(97,76,26))
杯形轮廓(颜色为rgb(97,76,26))
杯赛平局(获胜)
topoval=椭圆形(点(0.6,1.2),点(1.5,1.5))
topoval.setFill(“白色”)
拓扑值设置轮廓(颜色_rgb(97,76,26))
topoval.平局(赢)
咖啡=椭圆形(点(0.7,1.26),点(1.4,1.45))
咖啡.浓咖啡(颜色为rgb(71,54,14))
咖啡.咖啡色(rgb(71,54,14))
咖啡。抽签(赢)
tinycirc=圆(点(1.05,0.8),.3)
tinycirc.setFill(颜色_rgb(33158,87))
tinycirc.setOutline(“白色”)
tinycirc.平局(赢)
字母=文本(第(1.05,0.8)点,“B”)
字母.setStyle('粗体斜体
try:
click = win.getMouse()
if click.getX() > 4.2 and click.getX() < 5.8 and whitebagel >0 and wheatbagel >0:
subtotal = whitetotal+wheattotal+creamtotal+buttertotal+jellytotal+regulartotal+decaftotal
tax = .06
taxes = subtotal*tax
total = taxes+subtotal
subtotal = "$%0.2f" % (subtotal)
taxes = "$%0.2f" % (taxes)
total = "$%0.2f" % (total)
subtotaloutput.setText(subtotal)
taxoutput.setText(taxes)
totaloutput.setText(total)
#Coffee Cup Image
bottomoval = Oval(Point(0.7,0.4), Point(1.4, 0.7))
bottomoval.setFill(color_rgb(97,76,26))
bottomoval.setOutline(color_rgb(97,76,26))
bottomoval.draw(win)
cup = Rectangle(Point(0.7,0.5), Point(1.4,1.3))
cup.setFill(color_rgb(97,76,26))
cup.setOutline(color_rgb(97,76,26))
cup.draw(win)
topoval = Oval(Point(0.6,1.2), Point(1.5, 1.5))
topoval.setFill('white')
topoval.setOutline(color_rgb(97,76,26))
topoval.draw(win)
coffee = Oval(Point(0.7,1.26), Point(1.4, 1.45))
coffee.setFill(color_rgb(71,54,14))
coffee.setOutline(color_rgb(71,54,14))
coffee.draw(win)
tinycirc = Circle(Point(1.05,0.8), .3)
tinycirc.setFill(color_rgb(33,158,87))
tinycirc.setOutline('white')
tinycirc.draw(win)
letter = Text(Point(1.05,0.8),"B")
letter.setStyle('bold italic')
letter.setTextColor('white')
letter.setFace('courier')
letter.setSize(17)
letter.draw(win)
#Bagel
outerbagel = Oval(Point(1.8, 0.4), Point(2.7, 1))
outerbagel.setFill(color_rgb(191,157,61))
outerbagel.draw(win)
shadow = Oval(Point(2.1, 0.7), Point(2.4, 0.8))
shadow.setFill(color_rgb(130,102,26))
shadow.draw(win)
except:
errorWindow()
while(True):
click = win.getMouse()
if calculate button:
get text values
if not bagels:
errorWindow()
continue
calculate
elif quit button:
break