python简易计算器制作

window=Tk() #设置窗口对象
window.title(‘counting machine’)
window.geometry(“350x280”)
window[‘bg’]=‘red’

frame=LabelFrame(window,bg=‘yellow’,width=350,height=50)
frame.pack()
frame.place(x=0,y=0)
label=Label(frame,text=“1+1=2”,height=3,width=50,bg=‘yellow’)
label.pack() #显示框

#按钮.
def figure_dot():
global s
s=s+"."
label.config(text=s)
btn0=Button(window,text=".",width=4,command=figure_dot,bg=‘yellow’)
btn0.place(x=150,y=220) #按钮.
#按钮0
def figure_0():
global s
s=s+“0”
label.config(text=s)
btn0=Button(window,text=“0”,width=4,command=figure_0,bg=‘yellow’)
btn0.place(x=80,y=220) #按钮0
#按钮1
def figure_1():
global s
s=s+“1”
label.config(text=s)
btn1=Button(window,text=“1”,width=4,command=figure_1,bg=‘yellow’)
btn1.place(x=10,y=80) #按钮1
#按钮2
def figure_2():
global s
s=s+“2”
label.config(text=s)
btn2=Button(window,text=“2”,width=4,command=figure_2,bg=‘yellow’)
btn2.place(x=80,y=80)#按钮2
#按钮3
def figure_3():
global s
s=s+“3”
label.config(text=s)
btn3=Button(window,text=“3”,width=4,command=figure_3,bg=‘yellow’)
btn3.place(x=150,y=80)#按钮3
#按钮4
def figure_4():
global s
s=s+“4”
label.config(text=s)
btn4=Button(window,text=“4”,width=4,command=figure_4,bg=‘yellow’)
btn4.place(x=10,y=130)#按钮4
#按钮5
def figure_5():
global s
s=s+“5”
label.config(text=s)
btn5=Button(window,text=“5”,width=4,command=figure_5,bg=‘yellow’)
btn5.place(x=80,y=130)#按钮5
#按钮6
def figure_6():
global s
s=s+“6”
label.config(text=s)
btn6=Button(window,text=“6”,width=4,command=figure_6,bg=‘yellow’)
btn6.place(x=150,y=130)#按钮6
#按钮7
def figure_7():
global s
s=s+“7”
label.config(text=s)
btn7=Button(window,text=“7”,width=4,command=figure_7,bg=‘yellow’)
btn7.place(x=10,y=180)#按钮7
#按钮8
def figure_8():
global s
s=s+“8”
label.config(text=s)
btn8=Button(window,text=“8”,width=4,command=figure_8,bg=‘yellow’)
btn8.place(x=80,y=180)#按钮8
#按钮9
def figure_9():
global s
s=s+“9”
label.config(text=s)
btn9=Button(window,text=“9”,width=4,command=figure_9,bg=‘yellow’)
btn9.place(x=150,y=180)#按钮9

你可能感兴趣的:(python)