因为代码很长,我把代码放在这个链接中:http://textuploader.com/5xofp
以下是小代码:
from graphics import *
from math import *
def main():
win = GraphWin('Simple Calculator',400,600)
win.setBackground('slategray')
p1 = Point(10,70)
p2 = Point(390,10)
display_box = Rectangle(p1,p2)
display_box.draw(win)
text = Text(Point(190,30),"")
text.setStyle('italic')
text.setSize(15)
text.draw(win)
sqrt = Rectangle(Point(70,190),Point(120,140))
sqrt.draw(win)
sqrt1 = Text(Point(95,165),"√ ")
sqrt1.setStyle('italic')
sqrt1.setSize(36)
sqrt1.draw(win)
eq_sign = Rectangle(Point(170,510),Point(240,440))
eq_sign.draw(win)
eq = Text(Point(205,475),"=")
eq.setStyle('italic')
eq.setSize(36)
eq.draw(win)
num1 = Rectangle(Point(10,270),Point(80,200))
num1.draw(win)
num1_ = Text(Point(45,235),"1")
num1_.setStyle('italic')
num1_.setSize(36)
num1_.draw(win)
if 10<=mouse.x<=80 and 200<=mouse.y<=270:
text.setText(text.getText()+"1")
if 70<=mouse.x<=120 and 140<=mouse.y<=190:
text.setText(text.getText()+"sqrt(")
if 170<=mouse.x<=240 and 440<=mouse.y<=510:#=
try:
result = eval(text.getText())
except:
result = "ERROR"
text.setText(result)
main()
为什么当我输入sqrt(36)时,它会在文本中给出错误?我已经把它做成一根绳子了。 我的密码有错吗?你知道吗
这将用矩形对象覆盖数学模块的
sqrt
函数。尝试将此变量的名称更改为其他名称。你知道吗相关问题 更多 >
编程相关推荐