Skip to content

Instantly share code, notes, and snippets.

@athiyadeviyani
Created July 19, 2018 08:28
Show Gist options
  • Save athiyadeviyani/cf30f15d4ea7de03e300de411fbd71a1 to your computer and use it in GitHub Desktop.
Save athiyadeviyani/cf30f15d4ea7de03e300de411fbd71a1 to your computer and use it in GitHub Desktop.
Embarrassingly simple BMI calculator
from tkinter import *
from PIL import Image, ImageTk
window = Tk()
window.title("BMI Calculator")
window.geometry('720x1000')
lbl = Label(window, text = "Welcome to the BMI Calculator!", font = ("System", 20))
lbl.grid(column = 0, row = 0, columnspan = 2)
hlbl = Label(window, text = "Height (cm)", font = ("System", 14))
hlbl.grid(column = 0, row = 2)
height = Entry(window, width = 10, font = ("System", 14))
height.grid(column = 1 , row = 2)
wlbl = Label(window, text = "Weight (kg)", font = ("System", 14))
wlbl.grid(column = 0, row = 4)
weight = Entry(window, width = 10, font = ("System", 14))
weight.grid(column = 1 , row = 4)
r = Label(window, text = "Your BMI is", font = ("System", 14))
r.grid(column = 0, row = 12, columnspan = 2)
resultlabel = Label(window, text = "", font = ("System", 26))
resultlabel.grid(column = 0, row = 14, columnspan = 2)
condition = Label(window, text = "", font = ("System", 20))
condition.grid(column = 0, row = 16, columnspan = 2)
def clicked():
w = int(weight.get())
h = int(height.get())
bmi = w / ((h / 100) ** 2)
result = str(bmi)
resultlabel.configure(text = result)
if (bmi <= 18):
condition.configure(text = "You are UNDERWEIGHT!")
elif (bmi < 25):
condition.configure(text = "You are HEALTHY!")
elif (bmi < 30):
condition.configure(text = "You are OVERWEIGHT!")
elif (bmi < 40):
condition.configure(text = "You are OBESE!")
else:
condition.configure(text = "You are EXTREMELY OBESE!")
calculate = Button(window, text = "Calculate!", bg = "black", fg = "black", command = clicked, font = ("System",16), width = 30)
calculate.grid(column = 0, row = 8, columnspan = 2)
image = Image.open("bmi-chart.png").resize((700, 500), Image.ANTIALIAS)
photo = ImageTk.PhotoImage(image)
label = Label(image=photo)
label.image = photo # keep a reference!
label.grid(column = 0, row = 118, columnspan = 2)
window.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment