import tkinter as tk
from decimal import Decimal
import math
top=tk.Tk()
top.title("我是一个计算器")
top.geometry("350x400+150+150")
n=0#实现单击数字对应出现在文本框中defnclick():global n
n=n+1
text=bt['text']
text1.insert(n-1,text)defn1click():global n
n=n+1
text=bt1['text']
text1.insert(n-1,text)defn2click():global n
n=n+1
text=bt2['text']
text1.insert(n-1,text)defn3click():global n
n=n+1
text=bt3['text']
text1.insert(n-1,text)defn4click():global n
n=n+1
text=bt4['text']
text1.insert(n-1,text)defn5click():global n
n=n+1
text=bt5['text']
text1.insert(n-1,text)defn6click():global n
n=n+1
text=bt6['text']
text1.insert(n-1,text)defn7click():global n
n=n+1
text=bt7['text']
text1.insert(n-1,text)defn8click():global n
n=n+1
text=bt8['text']
text1.insert(n-1,text)defn14click():global n
n=n+1
text=bt14['text']
text1.insert(n-1,text)#实现单击符号对应出现在文本框中defn9click():global n
n=n+1
text=bt9['text']
text1.insert(n-1,text)defn10click():global n
n=n+1
text=bt10['text']
text1.insert(n-1,text)defn11click():global n
n=n+1
text=bt11['text']
text1.insert(n-1,text)defn12click():global n
n=n+1
text=bt12['text']
text1.insert(n-1,text)defn13click():global n
n=n+1
text=bt13['text']
text1.insert(n-1,text)#完成计算的函数defn15click():
text=text1.get()for i inrange(len(text)):if(text[i]=='.'):for i inrange(len(text)):if(text[i]=='+'):
p=Decimal(text[0:i:])try:
q=Decimal(text[i+1::])except:
text1.delete(0,tk.END)
text1.insert(0,"error")
result=p+q
text1.delete(0,tk.END)
text1.insert(0,result)if(text[i]=='-'):
p=Decimal(text[0:i:])try:
q=Decimal(text[i+1::])except:
text1.delete(0,tk.END)
text1.insert(0,"error")
result=p-q
text1.delete(0,tk