自分用

 #coding: utf-8

import tkinter as tk

 # 各ボタンが押された時、テキストボックスに入力
def func(v):
    text1.insert(tk.END,v)

 # Cボタンを押された時、計算式用テキストボックス1文字削除
def func_del():
    pos_end_prev = len(text1.get())-1  # 計算式末尾の1つ前
    text1.delete(pos_end_prev,tk.END)

 # ACボタンを押された時、計算式用テキストボックス全文字削除
def func_alldel():
    text1.configure(state=tk.NORMAL) # テキストボックス編集不可の場合あり、固定解除
    text2.configure(state=tk.NORMAL)
    text1.delete(0, tkinter.END)
    text2.delete(0, tkinter.END)

 # =ボタンを押された時
def equal_click():
    try:
        if text1.get():
            ans = eval(text1.get())
            if 99999999 < ans: # 結果が99999999上回るとき
              text2.delete(0, tk.END)
              text2.insert(tk.END,"桁数上限超過")
              text1.configure(state=tk.DISABLED) # テキストボックスの固定
              text2.configure(state=tk.DISABLED)
            elif ans < -99999999: # 結果が99999999下回るとき
              text2.delete(0, tk.END)
              text2.insert(tk.END,"-桁数上限超過")
              text1.configure(state=tk.DISABLED)
              text2.configure(state=tk.DISABLED)
            elif len(str(ans)) > 8: # 結果文字列が8文字超えるとき
              seisuu = len(str(round(ans)))
              syousuu = 8-seisuu
              ans = round(ans, syousuu) # 出力を8桁に制限
              text2.delete(0, tk.END)
              text2.insert(tk.END,str(ans))
            else:
              text2.delete(0, tk.END)
              text2.insert(tk.END,str(ans))
    except SyntaxError: # 計算エラー
        text2.delete(0, tk.END)
        text2.insert(tk.END,"SyntaxError")
    except ZeroDivisionError:  # 0割りエラー
        text2.delete(0, tk.END)        
        text2.insert(tk.END,"ZeroDivisionError")
   
 # enterキーが押されたとき
def click_enter(event):
    try:
        if text1.get():
            ans = eval(text1.get())
            if 99999999 < ans:
              text2.delete(0, tk.END)
              text2.insert(tk.END,"桁数上限超過")
              text1.configure(state=tk.DISABLED)
              text2.configure(state=tk.DISABLED)
            elif ans < -99999999:
              text2.delete(0, tk.END)
              text2.insert(tk.END,"-桁数上限超過")
              text1.configure(state=tk.DISABLED)
              text2.configure(state=tk.DISABLED)
            elif len(str(ans)) > 8:
              seisuu = len(str(round(ans)))
              syousuu = 8-seisuu
              ans = round(ans, syousuu)
              text2.delete(0, tk.END)
              text2.insert(tk.END,str(ans))
            else:
              text2.delete(0, tk.END)
              text2.insert(tk.END,str(ans))
    except SyntaxError:
        text2.delete(0, tk.END)
        text2.insert(tk.END,"SyntaxError")
    except ZeroDivisionError:
        text2.delete(0, tk.END)        
        text2.insert(tk.END,"ZeroDivisionError")
   

 # 計算ウィンドウ
win = tk.Tk()
win.title("電卓")
win.geometry('300x150')
      

 #ラベル作成
label = tk.Label(win)
label.place(x=50,y=50)

 #テキストボックス作成
text1 = tk.Entry(win,width=20) # 計算式
text1.place(x=100,y=0)
text1.focus_set() # キー入力のアクティブ
text1.bind('<Return>', click_enter) # enterキーでclick_enterへ

text2 = tk.Entry(win,width=20) # 計算結果
text2.place(x=100,y=30)

 #0～9ボタン作成
btn_0 = tk.Button(win, text="0", command=lambda: func("0")).grid(column=0, row=4)
btn_1 = tk.Button(win, text="1", command=lambda: func("1")).grid(column=0, row=3)
btn_2 = tk.Button(win, text="2", command=lambda: func("2")).grid(column=1, row=3)
btn_3 = tk.Button(win, text="3", command=lambda: func("3")).grid(column=2, row=3)
btn_4 = tk.Button(win, text="4", command=lambda: func("4")).grid(column=0, row=2)
btn_5 = tk.Button(win, text="5", command=lambda: func("5")).grid(column=1, row=2)
btn_6 = tk.Button(win, text="6", command=lambda: func("6")).grid(column=2, row=2)
btn_7 = tk.Button(win, text="7", command=lambda: func("7")).grid(column=0, row=1)
btn_8 = tk.Button(win, text="8", command=lambda: func("8")).grid(column=1, row=1)
btn_9 = tk.Button(win, text="9", command=lambda: func("9")).grid(column=2, row=1)

 #記号ボタン作成
btn_p = tk.Button(win, text="+", command=lambda: func("+")).grid(column=4, row=3)
btn_m = tk.Button(win, text="-", command=lambda: func("-")).grid(column=4, row=2)
btn_k = tk.Button(win, text="×", command=lambda: func("*")).grid(column=4, row=1)
btn_w = tk.Button(win, text="÷", command=lambda: func("/")).grid(column=4, row=0)
btn_e = tk.Button(win, text="=", command=equal_click).grid(column=4, row=4)
btn_s = tk.Button(win, text=".", command=lambda: func(".")).grid(column=1, row=4)

btn_AC = tk.Button(win, text='AC', command=func_alldel).grid(column=1, row=0)
btn_C = tk.Button(win, text="C", command=func_del).grid(column=0, row=0)

 #実行
win.mainloop()