用tkinter實現BMI計算

2021-10-11 21:46:52 字數 2812 閱讀 5350

import tkinter

import tkinter.messagebox

root = tkinter.tk(

)root.title(

'bmi計算器'

)root.geometry(

'400x400'

)bmi = tkinter.strin**ar(

)label = tkinter.label(root,text=

'bmi判斷'

)label.place(x=

10,y=

10,height=

30,width=80)

labelname = tkinter.label(root,text=

'姓名'

)labelname.place(x=

10,y=

60,height=

20,width=80)

labelage = tkinter.label(root,text=

'年齡'

)labelage.place(x=

10,y=

110,height=

20,width=80)

labelweight = tkinter.label(root,text=

'體重'

)labelweight.place(x=

10,y=

160,height=

20,width=80)

labelheight = tkinter.label(root,text=

'身高'

)labelheight.place(x=

10,y=

210,height=

20,width=80)

name = tkinter.strin**ar(root)

entryname = tkinter.entry(root,width=

150,textvariable=name)

entryname.place(x=

70,y=

60,height=

20,width=80)

age = tkinter.strin**ar(root)

entryage = tkinter.entry(root,width=

150,textvariable=age)

entryage.place(x=

70,y=

110,height=

20,width=80)

weight = tkinter.strin**ar(root)

entryweight = tkinter.entry(root,width=

150,textvariable=weight)

entryweight.place(x=

70,y=

160,height=

20,width=80)

height = tkinter.strin**ar(root)

entryheight = tkinter.entry(root,width=

150,textvariable=height)

entryheight.place(x=

70,y=

210,height=

20,width=80)

defmsgbox()

: 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指數是 偏瘦'

.format

(result=bmi.

set)

)elif bmi.

set<24:

tkinter.messagebox.showinfo(title=

'bmi計算結果'

, message=

'你的bmi指數是 正常'

.format

(result=bmi.

set)

)elif bmi.

set<30:

tkinter.messagebox.showinfo(title=

'bmi計算結果'

, message=

'你的bmi指數是 偏胖'

.format

(result=bmi.

set)

)else

: tkinter.messagebox.showinfo(title=

'bmi計算結果'

, message=

'你的bmi指數是 肥胖'

.format

(result=bmi.

set)

)return

button = tkinter.button(root,text=

'計算bmi'

,command=msgbox)

button.place(x=

10,y=

250,height=

30,width=80)

root.mainloop(

)

用python實現BMI判斷 問題

class bmi 定義乙個bmi類 def init self,name,age,weight,tall 初始化函式 self.name name self.age int age self.weight int weight self.tall float tall self.p self.we...

計算BMI指數

coding utf 8 height float input 請輸入您的身高 m weight float input 請輸入您的體重 kg bmi weight height height if bmi 29.9 print 您的bmi指數為 str bmi print 肥胖 else if b...

python之tkinter 實現簡易計算器

from tkinter import root tk root.maxsize 300,400 class createframe def init self,frame,width,height self.frame frame self.width width self.height heig...