-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBMI-Calculator.py
More file actions
34 lines (23 loc) · 802 Bytes
/
BMI-Calculator.py
File metadata and controls
34 lines (23 loc) · 802 Bytes
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
import tkinter
root = tkinter.Tk()
root.title("BMI Calculator")
# Create function(s)
def calculate_bmi():
kg = float(entry_kg.get())
height = float(entry_height.get())
bmi = round((kg / (height**2)) * 10000, 2)
label_result["text"] = f"BMI: {bmi}"
# Create GUI
label_kg = tkinter.Label(root, text="KG: ")
label_kg.grid(column=0, row=0)
entry_kg = tkinter.Entry(root)
entry_kg.grid(column=1, row=0)
label_height = tkinter.Label(root, text="HEIGHT: ")
label_height.grid(column=0, row=1)
entry_height = tkinter.Entry(root)
entry_height.grid(column=1, row=1)
button_calculate = tkinter.Button(root, text="Calculate", command=calculate_bmi)
button_calculate.grid(column=0, row=2)
label_result = tkinter.Label(root, text="BMI: ")
label_result.grid(column=1, row=2)
root.mainloop()