栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python实现窗口化计算bmi

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python实现窗口化计算bmi

from tkinter import *
from tkinter import messagebox
class BmiGui:
    def __init__(self,root):
        '''
        定义各种组件对象
        root: 窗口对象
        '''
        self.root=root
        self.height_label=Label(master=self.root,text='请输入身高(m):')
        self.weight_label=Label(master=self.root,text='请输入体重(w):')
        self.height_entry=Entry(master=self.root)
        self.weight_entry=Entry(master=self.root)

    def place(self):
        '''
        放置组件
        '''

        self.height_label.place(x=50,y=50)
        self.height_entry.place(x=160,y=50)
        self.weight_label.place(x=50,y=90)
        self.weight_entry.place(x=160,y=90)


    def cal_BMI(self):
        '''
        实现BMI计算
        '''
        h=eval(self.height_entry.get())
        w=eval(self.weight_entry.get())
        bmi=w/h**2
        if bmi<19:
            info='标准体型'
        else:
            info='超重体型'

        messagebox.showinfo(message='您的BMI为{:.2f},属于{}'.format(bmi,info))


if __name__=='__main__':
    top=Tk()
    top.title('计算体重指数')
    #设置窗口大小
    top.geometry('400x200')
    mybmi=BmiGui(top)
    mybmi.place()
    login_button=Button(master=top,command=mybmi.cal_BMI,text='计算BMI')
    login_button.place(x=140,y=110)

    top.mainloop()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/987342.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号