老样子,你得先安装tkinter的库
我用的是pycharm,里面自带tkinter
主要是我也不知怎么安装,你们可以去网上搜教程
废话不必多说,上源码!!
def Demo():
#运算函数
def math():
pop = e1.get()
a = eval(pop)
e1.delete(0,'end')
e1.insert('end',a)
#按钮板
s = tkinter.Tk()
s.title('计算器')
s.geometry('200x300')
s.resizable(width=False,height=False)
e1 = tkinter.Entry(s)
e1.place(x=1,y=1,width=200,height=50)
e2 = tkinter.Button(s,text='1',command=lambda:e1.insert("end",'1'))
e2.place(x=0,y=50,width=50,height=50)
e3 = tkinter.Button(s,text='2',command=lambda:e1.insert("end",'2'))
e3.place(x=50,y=50,width=50,height=50)
e4 = tkinter.Button(s,text='3',command=lambda:e1.insert("end",'3'))
e4.place(x=100,y=50,width=50,height=50)
e5 = tkinter.Button(s,text='4',command=lambda:e1.insert("end",'4'))
e5.place(x=0,y=100,width=50,height=50)
e6 = tkinter.Button(s,text='5',command=lambda:e1.insert("end",'5'))
e6.place(x=50,y=100,width=50,height=50)
e7 = tkinter.Button(s,text='6',command=lambda:e1.insert("end",'6'))
e7.place(x=100,y=100,width=50,height=50)
e8 = tkinter.Button(s,text='7',command=lambda:e1.insert("end",'7'))
e8.place(x=0,y=150,width=50,height=50)
e9 = tkinter.Button(s,text='8',command=lambda:e1.insert("end",'8'))
e9.place(x=50,y=150,width=50,height=50)
e10 = tkinter.Button(s,text='9',command=lambda:e1.insert("end",'9'))
e10.place(x=100,y=150,width=50,height=50)
e0 = tkinter.Button(s,text='C',command=lambda:e1.delete(0,"end"))
e0.place(x=150,y=50,width=50,height=50)
l0 = tkinter.Button(s, text='+',command=lambda:e1.insert("end",'+'))
l0.place(x=150, y=100, width=50, height=50)
p0 = tkinter.Button(s, text='-',command=lambda:e1.insert("end",'-'))
p0.place(x=150, y=150, width=50, height=50)
a0 = tkinter.Button(s, text='×',command=lambda:e1.insert("end",'*'))
a0.place(x=150, y=200, width=50, height=50)
k0 = tkinter.Button(s, text='0',command=lambda:e1.insert("end",'0'))
k0.place(x=0, y=200, width=50, height=50)
e0 = tkinter.Button(s, text='.',command=lambda:e1.insert("end",'.'))
e0.place(x=50, y=200, width=50, height=50)
im0 = tkinter.Button(s, text='÷',command=lambda:e1.insert("end",'/'))
im0.place(x=100, y=200, width=50, height=50)
u09 = tkinter.Button(s,text='=',command=lambda:math())
u09.place(x=0,y=250,width=100,height=50)
sop = tkinter.Button(s,text='查看作者',command=lambda:print('作者:wsw'))
sop.place(x=100,y=250,width=50,height=50)
tc = tkinter.Button(s,text='π',command=lambda:e1.insert("end",'3.141592653589793567909889621345'))
tc.place(x=150,y=250,width=50,height=50)
以上就是源码了,我这里没有调用函数,复制了记得调用函数!
否则代码不会运行!