import tkinter
import tkinter.messagebox
root=tkinter.Tk()
root.title="BMI测试"
button=tkinter.Button(root,text='测试',command=msgbox)
button.place(x=30,y=110,height=30,width=60)
lable=tkinter.Lable(root,text='name')
lable.place(x=20,y=10,height=20,width=40)
lable=tkinter.Lable(root,text='age')
lable.place(x=20,y=40,height=20,width=40)
lable=tkinter.Lable(root,text='weight')
lable.place(x=20,y=70,height=20,width=40)
lable=tkinter.Lable(root,text='height')
lable.place(x=20,y=100,height=20,width=40)
name=tkinter.StringVar(root)
entryname=tkinter.Entry(root,width=80,textvariable=name)
entryname.place(x=70,y=10,width=80,height=20)
age=tkinter.StringVar(root)
entryage=tkinter.Entry(root,width=80,textvariable=age)
entryage.place(x=70,y=40,width=80,height=20)
weight=tkinter.StringVar(root)
entryweight=tkinter.Entry(root,width=80,textvariable=weight)
entryweight.place(x=70,y=70,width=80,height=20)
height=tkinter.StringVar(root)
entryheight=tkinter.Entry(root,width=80,textvariable=height)
entryheight.place(x=70,y=100,width=80,height=20)
def msgbox():
bmi.set = round(float(entryWeight.get())/(float(entryHeight.get())*float(entryHeight.get())),2)
if bmi.set<18.5:
tkinter.messagebox.showinfo(title='BMI计算结果', message='你的BMI指数是 {result} 偏瘦'.format(result=bmi.set))
elif bmi.set<24:
tkinter.messagebox.showinfo(title='BMI计算结果', message='你的BMI指数是 {result} 正常'.format(result=bmi.set))
elif bmi.set<30:
tkinter.messagebox.showinfo(title='BMI计算结果', message='你的BMI指数是 {result} 偏胖'.format(result=bmi.set))
else :
tkinter.messagebox.showinfo(title='BMI计算结果', message='你的BMI指数是 {result} 肥胖'.format(result=bmi.set))
return
root.maxsize(1000,1000)
root.minsize(300,300)
root.mainloop() #启动主窗口
BMI+tkinter
最新推荐文章于 2022-04-11 14:24:34 发布