importtkinterastkwindow=tk.Tk()window.title('计算器')window.geometry('360x435')window.attributes("-alpha",0.95)window.resizable(0,0)#窗口大小固定,不能缩放var=tk.StringVar()frm_1=tk.Frame(window,width=360,height=115,bg='CadetBlue').place(x=0,y=0,anchor=tk.NW)#数字显示区frm_2=tk.Frame(window,width=270,height=240,bg='DarkSeaGreen').place(x=0,y=115,anchor=tk.NW)#数字键盘frm_3=tk.Frame(window,width=90,height=320,bg='Beige').place(x=270,y=115,anchor=tk.NW)#加减乘除frm_4=tk.Frame(window,width=270,height=80,bg='CadetBlue').place(x=0,y=355,anchor=tk.NW)#不可循环输出的var_result=tk.StringVar()var_dian=tk.StringVar()var_dian.set('.')defname(u):u='var'+str(u)returnu#数字显示区I=tk.Entry(frm_1,textvariable=var_result,font=('Arial',40),bg='grey')I.place(x=0,y=0,width=360,height=115)#获取数字显示区的文字#函数部分#计算结果的defshow_result():result=I.get()print(eval(result))defdelete():f.delete(1.0,tk.END)defget():passnum=1#数字键盘,可循环显示的forjinrange(3):foriinrange(3):m=0+(i)*90n=115+(j)*80b=tk.Button(frm_2,text=num,bg='WhiteSmoke',font=('Arial','20'),command=get)b.place(x=m,y=n,width=90,height=80)num=num+1#数字键盘,不可循环显示的v=0a=tk.Button(frm_4,textvariable=var_dian,bg='Gainsboro',font=('20')).place(x=0,y=355,width=90,height=80)b=tk.Button(frm_4,text='=',bg='Gainsboro',font=('20'),command=show_result).place(x=180,y=355,width=90,height=80)f=tk.Button(frm_4,text='0',bg='WhiteSmoke',font=('Arial','20')).place(x=90,y=355,width=90,height=80)#加减乘除q=0forpin['+','-','*','/']:e=tk.Button(frm_3,text=p,bg='Gainsboro',font=('20')).place(x=270,y=115+q*80,width=90,height=80)q=q+1window.mainloop()
撒科打诨
皈依舞
相关分类