Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created GUI based BMI Calculator using python tkinter #7309

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}
172 changes: 125 additions & 47 deletions Program's_Contributed_By_Contributors/Python_Programs/BMI Calculator.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,127 @@
from tkinter import *
from tkinter import ttk

#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 to display the BMI Value
ans=ttk.Label(root, text="")
ans.grid(row=5,column=1)

#label to display the status if healthy or overweight
label2= ttk.Label(root, text="")
label2.grid(row=6, column=1)

#label to display error message
label=ttk.Label(root,text="")
label.grid(row = 4, column=1)

#Function to check if the entry is float or not
def isfloat(x):
try:
float(x)
return True
except:
return False

#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():
wtg=weight.get()
if(weight_value.get()==weight_options[1]):
label.config(text="")
if isfloat(wtg):
ret = float(weight.get())
return ret
else:
weight.delete(0,END)
weight.insert(0,"SNYTAX ERROR")
elif(weight_value.get()==weight_options[2]):
label.config(text="")
if isfloat(wtg):
ret = float(weight.get())*0.453592
return ret
else:
weight.delete(0,END)
weight.insert(0,"SNYTAX ERROR")
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():
htg =height.get()
if(height_value.get()==height_options[1]):
if isfloat(htg):
ret= float(height.get())
return ret
else:
height.delete(0,END)
height.insert(0,"SYNTAX ERROR")
elif(height_value.get()==height_options[2]):
if isfloat(htg):
ret= float(height.get())*0.3048
return ret
else:
height.delete(0,END)
height.insert(0,"SYNTAX ERROR")
elif(height_value.get()==height_options[3]):
if isfloat(htg):
ret= float(height.get())/100
return ret
else:
height.delete(0,END)
height.insert(0,"SYNTAX ERROR")
else:
label.config(text="Please select a valid unit for height")

#Function to calculate BMI
def fun():
wt=enter_wt()
ht=enter_ht()
bmi=None
try:
bmi= float(wt)/(float(ht)*float(ht))
ans.config(text = "The BMI is: " + str(bmi))
if( int(wt) > 0 and round(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")
except:
ans.config(text="")
label2.config(text="")
pass

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

root.mainloop()