Skip to content

Instantly share code, notes, and snippets.

@athiyadeviyani
Created July 19, 2018 08:28

Revisions

  1. athiyadeviyani created this gist Jul 19, 2018.
    59 changes: 59 additions & 0 deletions bmiapp.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    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()