【发布时间】:2017-04-28 21:29:56
【问题描述】:
我正在为一个学校项目制作一个计算器,老师告诉我该怎么做,它奏效了。或者我想当我清理程序时我意识到它只能工作“+”并且没有其他按钮。任何帮助将不胜感激。
tempstr=my_text.get()
loopval=len(tempstr)
op=tempstr.index("+")
if (op>0):
leftnum=tempstr[0:op]
rightnum=tempstr[op+1:loopval+1]
answe=int(leftnum)+int(rightnum)
print (answe)
my_text.insert(END,str(answe))
op=tempstr.index("-")
if (op>0):
leftnum=tempstr[0:op]
rightnum=tempstr[op+1:loopval+1]
answe=int(leftnum)-int(rightnum)
print (answe)
my_text.insert(END,str(answe))
op=tempstr.index("*")
if (op>0):
leftnum=tempstr[0:op]
rightnum=tempstr[op+1:loopval+1]
answe=int(leftnum)*int(rightnum)
print (answe)
my_text.insert(END,str(answe))
op=tempstr.index("/")
if (op>0):
leftnum=tempstr[0:op]
rightnum=tempstr[op+1:loopval+1]
answe=int(leftnum)/int(rightnum)
print (answe)
my_text.insert(END,str(answe))
【问题讨论】:
标签: python-3.x tkinter calculator