-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (45 loc) · 1.62 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import tkinter as tk
from tkinter import messagebox
root = tk.Tk()
root.title("BMI Calculator")
calc_method = tk.StringVar(value="metric")
weight_label = tk.Label(root, text="Weight in kg: ")
weight_label.pack()
weight_entry = tk.Entry(root)
weight_entry.pack()
height_label = tk.Label(root, text="Height in cm: ")
height_label.pack()
height_entry = tk.Entry(root)
height_entry.pack()
def switch_units():
global calc_method
if calc_method.get() == "metric":
calc_method.set("imperial")
weight_label.config(text="Weight (lbs):")
height_label.config(text="Height (in):")
else:
calc_method.set("metric")
weight_label.config(text="Weight (kg):")
height_label.config(text="Height (cm):")
unit_button = tk.Button(root, text="Switch Units", command=switch_units)
unit_button.pack(side="top")
def calculate_bmi():
weight = float(weight_entry.get())
height = float(height_entry.get())
if calc_method.get() == 'metric':
bmi = weight / (height/100)**2
protien_intake = weight * 0.5
fat_intake = weight * 0.5
total_protien_fat = protien_intake + fat_intake
else:
bmi = (weight * 703) / height**2
protien_intake = weight * 2
fat_intake = weight * 0.88
total_protien_fat = protien_intake + fat_intake
result_label.config(text="BMI: {:.1f}".format(bmi))
calculate_button = tk.Button(root, text="Calculate", command=calculate_bmi)
calculate_button = tk.Button(root, text="Calculate BMI", command=calculate_bmi)
calculate_button.pack()
result_label = tk.Label(root, text="BMI: ")
result_label.pack()
root.mainloop()