-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adfa11f
commit b380e08
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import tkinter as tk | ||
|
||
def calculate_bmi(): | ||
height = float(height_entry.get()) | ||
weight = float(weight_entry.get()) | ||
bmi = weight / (height ** 2) | ||
result_label.config(text=f"BMI: {bmi:.2f}") | ||
|
||
# Create the main window | ||
root = tk.Tk() | ||
root.title("BMI Calculator") | ||
|
||
# Create and configure the widgets | ||
height_label = tk.Label(root, text="Height (m):") | ||
height_label.pack() | ||
|
||
height_entry = tk.Entry(root) | ||
height_entry.pack() | ||
|
||
weight_label = tk.Label(root, text="Weight (kg):") | ||
weight_label.pack() | ||
|
||
weight_entry = tk.Entry(root) | ||
weight_entry.pack() | ||
|
||
calculate_button = tk.Button(root, text="Calculate BMI", command=calculate_bmi) | ||
calculate_button.pack() | ||
|
||
result_label = tk.Label(root, text="") | ||
result_label.pack() | ||
|
||
# Start the main event loop | ||
root.mainloop() |