代码
import tkinter
win=tkinter.Tk()
win.title("BMI计算机")
win.geometry("300x400+200+300")
l1=tkinter.Label(win,text="请输入身高(m):")
l2=tkinter.Label(win,text="请输入体重:")
e1=tkinter.Entry(win)
l1.pack()
e1.pack()
e2=tkinter.Entry(win)
l2.pack()
e2.pack()
#产生列表
listbox1 = tkinter.Listbox(win)
listbox1.pack()
def click_button():
weight=float(e2.get())
hight=float(e1.get())
BMI=weight/hight**2
if BMI<=18.4:
text2="您的体重偏瘦"
elif 18.5 <= BMI <= 23.9:
text2 = "您的体重正常"
elif 24.0<=BMI<=27.9:
text2="您的体重偏胖"
elif BMI>=28.0:
text2=("您的体重肥胖")
text0="身高:"+str(hight)+"体重:"+str(weight)
text1="BMI为:"+str(BMI)
listbox1.insert(0,text0)
listbox1.insert(1,text1)
listbox1.insert(2,text2)
b1=tkinter.Button(win,text="计算BMI",command=click_button)
b1.pack()
win.mainloop()