from tkinter import *
import tkinter as tk
def add():
entry1.insert(len(entry1.get()), '+')
def minus():
entry1.insert(len(entry1.get()),'-')
def multiplication():
entry1.insert(len(entry1.get()), '*')
def division():
entry1.insert(len(entry1.get()),'/')
def answer():
entry1.insert(len(entry1.get()),'='+str(eval(entry1.get())))
def clear():
entry1.delete(0, "end")
entry1.insert(0, "0")
def delete():
entry1.delete(0,"end")
def del_the_last_singel_num():
entry1.delete(len(entry1.get())-1, "end")
def getter0():
entry1.insert(len(entry1.get()),0)
def getter1():
if entry1.get()=='0':
entry1.delete(0, "end")
entry1.insert(len(entry1.get()),1)
def getter2():
if entry1.get()=='0':
entry1.delete(0, "end")
entry1.insert(len(entry1.get()),2)
def getter3():
if entry1.get()=='0':
entry1.delete(0, "end")
entry1.insert(len(entry1.get()),3)
def getter4():
if entry1.get()=='0':
entry1.delete(0, "end")
entry1.insert(len(entry1.get()),4)
def getter5():
if entry1.get()=='0':
entry1.delete(0, "end")
entry1.insert(len(entry1.get()),5)
def getter6():
if entry1.get()=='0':
entry1.delete(0, "end")
entry1.insert(len(entry1.get()),6)
def getter7():
if entry1.get()=='0':
entry1.delete(0, "end")
entry1.insert(len(entry1.get()),7)
def getter8():
if entry1.get()=='0':
entry1.delete(0, "end")
entry1.insert(len(entry1.get()),8)
def getter9():
if entry1.get()=='0':
entry1.delete(0, "end")
entry1.insert(len(entry1.get()),9)
def dot():
entry1.insert(len(entry1.get()), ".")
win = tk.Tk()
win.title("计算器")
win.geometry("300x450")
entry1 = tk.Entry(win,width=10)
entry1.insert(0,"0")
entry1.place(x=0,y=0,width=300,height=75)
b01 = Button(win, text="C",command=clear).place(x=0,y=75,width=75,height=75)
b02 = Button(win, text="DEL",command = delete).place(x=75,y=75,width=75,height=75)
b04 = Button(win, text="/",command =division).place(x=225,y=75,width=75,height=75)
b1 = Button(win, text="7",command = getter7).place(x=0,y=150,width=75,height=75)
b2 = Button(win, text="4",command = getter4).place(x=0,y=225,width=75,height=75)
b3 = Button(win, text="1",command = getter1).place(x=0,y=300,width=75,height=75)
b4 = Button(win, text="8",command = getter8).place(x=75,y=150,width=75,height=75)
b5 = Button(win, text="5",command = getter5).place(x=75,y=225,width=75,height=75)
b6 = Button(win, text="2",command = getter2).place(x=75,y=300,width=75,height=75)
b7 = Button(win, text="9",command = getter9).place(x=150,y=150,width=75,height=75)
b8 = Button(win, text="6",command = getter6).place(x=150,y=225,width=75,height=75)
b9 = Button(win, text="3",command = getter3).place(x=150,y=300,width=75,height=75)
b11 = Button(win, text="*",command = multiplication).place(x=225,y=150,width=75,height=75)
b12 = Button(win, text="-",command = minus).place(x=225,y=225,width=75,height=75)
b13 = Button(win, text="+",command = add).place(x=225,y=300,width=75,height=75)
b14 = Button(win, text="0",command = getter0).place(x=0,y=375,width=75,height=75)
b15 = Button(win, text=".",command = dot).place(x=75,y=375,width=75,height=75)
b16 = Button(win, text="=",command=answer).place(x=150,y=375,width=150,height=75)
mainloop()