Skip to content

Commit

Permalink
Created GUI based BMI Calculator using python tkinter
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpanmukherjee3110 committed Nov 17, 2023
1 parent d666b45 commit 78d797a
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 47 deletions.
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "windows-gcc-x86",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "C:/MinGW/bin/gcc.exe",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x86",
"compilerArgs": [
""
]
}
],
"version": 4
}
32 changes: 32 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
},
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "c:/Users/ARPAN MUKHERJEE/Hacktoberfest2023",
"program": "c:/Users/ARPAN MUKHERJEE/Hacktoberfest2023/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
59 changes: 59 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,82 @@
from tkinter import *
from tkinter import ttk
import math

#input height
a= int(input((" Height in 1.inches or 2. feet and inches or 3.centimeters? choose and type 1 or 2 or 3 ->")))

if a==1:
Height = float(input(" Enter your height: "))
Height*=2.54
elif ( a==2 ):
Height_1 = str(input(" Enter in this format: 5'4 or foot'inches ->" ))
Height = float(Height_1[0]) *12 *2.54 + float(Height_1[2]) *2.54


#input weight
b= int( input (" Weight in 1.kg or 2.pounds? choose and type 1 or 2 ->"))

Weight = float( input(" Enter your Weight-> "))
if b==2:
Weight*=0.453592

#convert height into metres
Height = Height / 100

#calculate BMI
BMI = Weight / (Height*Height)

#printing BMI
print(f"Your Body Mass Index is: {BMI}")

#printing results
if( BMI > 0):
if( BMI <= 16 ):
print("You are severely underweight")
elif( BMI <= 17 ):
print("You are moderately underweight")
elif( BMI <= 18.5 ):
print("You are mildly underweight")
elif ( BMI <= 25 ):
print("You are healthy")
elif ( BMI <= 30 ):
print("You are overweight")
elif ( BMI <= 35 ):
print("You belong to obesity class I")
elif ( BMI <= 40 ):
print("You belong to obesity class II")
root=Tk()
root.title("BMI Calculator")
root.geometry("668x400")

label=ttk.Label(root,text="")
label.grid(row = 4, column=1)

#Enter Weight:
ttk.Label(root, text="Enter Your Weight").grid(row=0, column=0, padx=20)
weight=ttk.Entry(root, width=45)
weight.grid(row = 0, column = 1, padx=30, pady = 20)
weight_options=["Select a Unit","Weight in Kilograms (kg)","Weight in Pounds (lb)"]
weight_value=StringVar(root)
ttk.OptionMenu(root, weight_value, *weight_options).grid(row=0, column=2)
def enter_wt():
if(weight_value.get()==weight_options[1]):
label.config(text="")
return float(weight.get())
if(weight_value.get()==weight_options[2]):
label.config(text="")
return float(weight.get())*0.453592
else:
print("You belong to obesity class III")
else:
print("Enter valid details")

label.config(text="Please select a valid unit for weight")

#Enter Height:
ttk.Label(root, text="Enter Your Height").grid(row=1, column=0)
height=ttk.Entry(root, width=45)
height.grid(row=1, column=1, padx=30, pady=20)
height_options=["Select a Unit","Height in Metres (m)","Height in Feet (ft)", "Height in Centimetres (cms)"]
height_value=StringVar(root)
ttk.OptionMenu(root, height_value, *height_options).grid(row=1, column=2)
def enter_ht():
if(height_value.get()==height_options[1]):
return float(height.get())
if(height_value.get()==height_options[2]):
return float(height.get())*0.3048
if(height_value.get()==height_options[3]):
return float(height.get())/100.0
else:
label.config(text="Please select a valid unit for height")

ans=ttk.Label(root, text="")
ans.grid(row=5,column=1)
label2= ttk.Label(root, text="")
label2.grid(row=6, column=1)

def fun():
wt=enter_wt()
ht=enter_ht()
bmi= float(wt)/(float(ht)*float(ht))
ans.config(text = "The BMI is: " + str(bmi))
if( math.ceil(wt) > 0 and math.ceil(ht) > 0):
if( bmi <= 16 ):
label2.config(text="You are severely underweight")
elif( round(bmi) <= 17 ):
label2.config(text="You are moderately underweight")
elif( round(bmi) <= 18.5 ):
label2.config(text="You are mildly underweight")
elif ( round(bmi) <= 25 ):
label2.config(text="You are healthy")
elif ( round(bmi) <= 30 ):
label2.config(text="You are overweight")
elif ( round(bmi) <= 35 ):
label2.config(text="You belong to obesity class I")
elif ( round(bmi) <= 40 ):
label2.config(text="You belong to obesity class II")
else:
label2.config(text="You belong to obesity class III")
else:
ans.config(text="")
label2.config(text="Enter valid details")

button =ttk.Button(root, text='''
Calculate BMI
''', command=fun)
button.grid(row=3, column=1)

root.mainloop()

0 comments on commit 78d797a

Please sign in to comment.