from tkinter import * a=Tk() a.title('BMI計(jì)算') a.geometry('400x40
from tkinter import *
a=Tk()
a.title('BMI計(jì)算')
a.geometry('400x400')
L1=Label(a,text="身高(m):")
L2=Label(a,text="體重(kg):")
L1.grid(row=0, column=0)
L2.grid(row=1, column=0)
H=Entry(a,width=30)
H.grid(row=0, column=1)
W=Entry(a,width=30)
W.grid(row=1, column=1)
L3=Label(a,text='')
L4=Label(a,text='')
L3.grid(row=2,column=1)
L4.grid(row=3,column=1)
def u():
? ? m=float(H.get())
? ? n=float(W.get())
? ? s=n/m**2
? ? L3.config(text=str(s))
? ? if s<18.5:
? ? ? ? L4.config(text='體重過輕')
? ? elif s>=18.5 and s<24.9:
? ? ? ? L4.config(text='正常范圍')
? ? elif s>=24.9 and s<29.9:
? ? ? ? L4.config(text='體重過重')
? ? else :
? ? ? ? L4.config(text='肥胖')
J=Button(a,text='計(jì)算',command=u)
J.grid(row=4, column=1)
mainloop()
標(biāo)簽: