forked from OpenBMB/ChatDev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
36 lines (36 loc) · 1.46 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
'''
This is the main file of the BMI calculator application.
'''
import tkinter as tk
from bmi_calculator import BMICalculator
class BMIApplication(tk.Tk):
def __init__(self):
super().__init__()
self.title("BMI Calculator")
self.geometry("300x200")
self.bmi_calculator = BMICalculator()
self.weight_label = tk.Label(self, text="Weight (kg):")
self.weight_label.pack()
self.weight_entry = tk.Entry(self)
self.weight_entry.pack()
self.height_label = tk.Label(self, text="Height (cm):")
self.height_label.pack()
self.height_entry = tk.Entry(self)
self.height_entry.pack()
self.calculate_button = tk.Button(self, text="Calculate", command=self.calculate_bmi)
self.calculate_button.pack()
self.result_label = tk.Label(self, text="")
self.result_label.pack()
def calculate_bmi(self):
try:
weight = float(self.weight_entry.get())
height = float(self.height_entry.get()) / 100
bmi = self.bmi_calculator.calculate_bmi(weight, height)
self.result_label.config(text=f"BMI: {bmi:.2f}")
except ValueError:
self.result_label.config(text="Invalid input. Please enter numeric values for weight and height.")
except ZeroDivisionError:
self.result_label.config(text="Invalid input. Height cannot be zero.")
if __name__ == "__main__":
app = BMIApplication()
app.mainloop()