Untitled
unknown
python
a year ago
1.5 kB
18
Indexable
import tkinter
class BMI:
def __init__(self):
self.mw = tkinter.Tk()
# cteate an entry
self.label1= tkinter.Label(self.mw, text='Weight')
self.entry1 = tkinter.Entry(self.mw, width= 15)
self.label2 = tkinter.Label(self.mw, text='Height')
self.entry2 = tkinter.Entry(self.mw, width= 15)
# label for calculate button
self.lab_var = tkinter.StringVar()
self.lab1 = tkinter.Label(self.mw, textvariable= self.lab_var)
self.button = tkinter.Button(self.mw, text = 'Calculate BMI', command = self.get_BMI)
self.lab1.grid(row=2, column=0)
self.label1.grid(row=0, column=0)
self.entry1.grid(row=0, column=1)
self.label2.grid(row=1, column=0)
self.entry2.grid(row=1, column=1)
self.button.grid(row=2, column=2)
tkinter.mainloop()
def get_BMI(self):
BMI = float(self.entry1.get())/ (float(self.entry2.get()) * float(self.entry2.get()))
if BMI < 18.5:
message = f'Your BMI is {BMI}. You are underweight'
elif 18.5 < BMI < 24.9:
message = f'Your BMI is {BMI}. You are healthy'
elif 25.0 < BMI < 29.9:
message = f'Your BMI is {BMI}. You are Overweight'
else:
message = f'Your BMI is {BMI}. You are obese'
self.lab_var.set(message)
gui = BMI()Editor is loading...
Leave a Comment