BMI CALCULATER
from tkinter import *
import tkinter as tk
from tkinter import messagebox
window = Tk()
window.title("BMI Calculator")
window.config(bg = "#CCE8F9", padx=5, pady=5)
framecolour = "White"
padding = 7
frame = tk.Frame(window)
frame.config(bg = framecolour, padx=10, pady=10)
frame.grid(column = 0, row = 0, padx=20, pady=10)
frame.pack()
Heading1 = Label (frame, text = "Calculate your BMI")
Heading1.grid(column = 0, row = 0, columnspan = 4, pady = padding)
Heading1.config(width = 24, height = 2, bg = "#CCE8F9", font = ("Calibri bold", 24), fg = "black",relief = "groove")
# Ths is For Name : Lable & Entry.
Name_Label = Label (frame, text = "Enter your Name :")
Name_Label.grid(column = 0, row = 2, columnspan = 2, pady = padding)
Name_Label.config(width = 26, height = 2, bg ="#EDF7FD", fg = "black", \
font = ("Calibri bold", 14), justify = "center",relief = "groove")
Name_var = StringVar()
Name = Entry(frame,textvariable = Name_var, font=('calibre',10,'normal'))
Name.grid(column = 3, row = 2, sticky="e")
Name.config(width = 6, bg = "white", fg = "black", relief = "ridge", justify = "center", font = ("Calibri", 26))
# # Ths is for Weight.
Weight_Label = Label (frame, text = "Enter your weight in Pound \n to the right:")
Weight_Label.grid(column = 0, row = 4, columnspan = 2, pady = padding)
Weight_Label.config(width = 26, height = 2, bg ="#EDF7FD", fg = "black", \
font = ("Calibri bold", 14), justify = "center",relief = "groove")
Weight_var = DoubleVar()
Weight = Entry(frame,textvariable = Weight_var, font=('calibre',10,'normal'))
# Weight = Entry (frame)
Weight.grid(column = 3, row = 4, sticky="e")
Weight.config(width = 4, bg = "white", fg = "black", relief = "ridge", justify = "center", font = ("Calibri", 26))
#This is for Height (Feet) : Lable & Entry.
Height_Label = Label (frame, text = "Enter your height in Feet \n to the right:")
Height_Label.grid(column = 0, row = 6, columnspan = 2, pady = padding)
Height_Label.config(width = 26, height = 2, bg ="#EDF7FD" , fg = "black", \
font = ("Calibri bold", 14), justify = "center",relief = "groove")
Height_var = DoubleVar()
Height = Entry(frame,textvariable = Height_var, font=('calibre',10,'normal'))
Height.grid(column = 3, row = 6, sticky = "e")
Height.config(width = 4, bg = "white", fg = "black", justify = "center", font = ("Calibri", 26))
#This is for Height (Inches) : Lable & Entry.
Height1_Label = Label (frame, text = "Enter your height in Inches \n to the right:")
Height1_Label.grid(column = 0, row = 8, columnspan = 2, pady = padding)
Height1_Label.config(width = 26, height = 2, bg ="#EDF7FD" , fg = "black", \
font = ("Calibri bold", 14), justify = "center",relief = "groove")
Height1_var = DoubleVar()
Height1 = Entry(frame,textvariable = Height1_var, font=('calibre',10,'normal'))
Height1.grid(column = 3, row = 8, sticky = "e")
Height1.config(width = 4, bg = "white", fg = "black", justify = "center", font = ("Calibri", 26))
#This is for Gender : Lable & Entry.
Gender_Label = Label (frame, text = "choose your gender :")
Gender_Label.grid(column = 0, row = 9, columnspan = 2, pady = padding)
Gender_Label.config(width = 26, height = 2, bg ="#EDF7FD" , fg = "black", \
font = ("Calibri bold", 14), justify = "center",relief = "groove")
v = IntVar()
Gender_Male = Radiobutton(frame, text="Male", variable=v, value=1)
Gender_Female = Radiobutton(frame, text="Female", variable=v, value=2)
Gender_Male.grid(column = 2, row = 9)
Gender_Male.config(width = 5, bg="White", fg = "black", justify = "center",font = ("Calibri", 12))
Gender_Female.grid(column = 3, row = 9)
Gender_Female.config(width = 5, bg="White", fg = "black", justify = "center", font = ("Calibri", 12))
v.set(1)
def Calculate():
name=Name_var.get()
weight=Weight_var.get()
feet=Height_var.get()
inches = Height1_var.get()
print("=============================================")
print("The name is : ", name)
print("The weight is : ", weight)
print("The Feet is : ", feet)
print("The Inches is : ", inches)
'''here weight is in pound (lsb) and height in inches (in).
so first calculate height in inches (1 feet =12 inche) and
then bmi = (weight / height**2)*703 is formula for bmi.
'''
height = (feet*12)+inches
bmi = float((weight*703)/(height**2))
print("Your BMI is : %.2f " % bmi)
# Updates the status label
if bmi < 18.5:
print("You are Underweight")
messagebox.showinfo('Message', 'You are Underweight')
if 18.5 <= bmi < 25:
print("You are Normal or Healthy Weight")
messagebox.showinfo('Message', 'You are Normal or Healthy Weight')
if 25 <= bmi < 30:
print("You are Overweight")
messagebox.showinfo('Message', 'You are Overweight')
if 30<= bmi > 30:
print("You are Obese")
messagebox.showinfo('Message', 'You are Obese')
print("=============================================")
PressMe = Button(frame, text = "Calculate \n your BMI",command = Calculate )
PressMe.grid(row = 10, column = 1, columnspan = 2, pady = padding, sticky = "w")
PressMe.config(width = 19, height = 2, bg = "dark blue", fg = "white",\
bd = 3, relief = "raised",font = ("Calibri bold", 14, "bold"))
Heading = Label(frame, text = "Your BMI is:")
Heading.grid(column = 0, row = 12, columnspan = 4, pady = padding, sticky = "w")
Heading.config(width = 41, height = 2, bg = "white", fg = "black",\
font = ("Calibri bold", 14))
close = Button(frame, text="Close",command=window.destroy)
close.grid(column = 1, row = 14, columnspan = 2, pady = padding, sticky = "nsew")
close.config(width = 5, height = 1, bg = "#CCE8F9", fg = "black",\
font = ("Calibri bold", 14, "bold"))
window.mainloop()
Comments
Post a Comment