-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmi_calculator_V_04.py
93 lines (68 loc) · 3.8 KB
/
bmi_calculator_V_04.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import customtkinter
# general settings for appearance of gui
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("dark-blue")
app = customtkinter.CTk()
app.geometry("430x400")
app.title("Wilkommen in meinem BMI-Rechner.")
frame1 = customtkinter.CTkFrame(master=app, fg_color="#ad3f37", border_color="#240d0c", border_width=2)
hinweis_label = customtkinter.CTkLabel(master = frame1, text = "Hinweis: Der BMI dient lediglich einer Einschätzung,\n"
"hat aber keinen Anspruch auf Richtigkeit.\n"
"Sind Sie beispielsweise sehr muskolös, kann fälsch- \n"
"lich eine Einschätzung in die Kategorie 'Übergewicht' erfolgen.")
# basic fields for needed input for bmi
frame2 = customtkinter.CTkFrame(master=app)
frame22 = customtkinter.CTkFrame(master=frame2, border_color="#ad3f37", border_width=1)
hinweis2_label = customtkinter.CTkLabel(master=frame22, text = "Bitte keine Kommata eingeben")
weight_title = customtkinter.CTkLabel(master=frame2, text = "Ihr Körpergewicht in Kilogramm: ", )
weight_entry = customtkinter.CTkEntry(master=frame2, placeholder_text = "z.B.: 90.6")
height_title = customtkinter.CTkLabel(master=frame2, text = "Ihre Körpergröße in Metern: ")
height_entry = customtkinter.CTkEntry(master=frame2, placeholder_text = "z.B.: 1.85")
# function behind button press to calculate bmi
def output_calc():
# getting input from input fields and transforming them to floats
input_weight = float(weight_entry.get())
input_height = float(height_entry.get())
# math logic of bmi
middle = input_weight / input_height ** 2
output_number = round(middle, 2)
# determining result
if output_number < 18.5:
output = "Untergewicht"
output_field.configure(text= output)
elif output_number >= 18.5 and output_number <= 24.9:
output ="Normalgewicht"
output_field.configure(text= output)
elif output_number >= 25 and output_number <= 34.9:
output = "Übergewicht"
output_field.configure(text= output)
else:
output = "Starkes oder extremes Übergewicht"
output_field.configure(text= output)
# defining variables for the coming modules
output = "Hier erscheint Ihr Ergebnis"
output_number = ""
# output and button
frame3 = customtkinter.CTkFrame(app, fg_color = "#383838")
output_field = customtkinter.CTkLabel(frame3, text = output, width = 340, font = ("", 15))
converter_button = customtkinter.CTkButton(app,
text = "BMI berechnen",
command = output_calc,
hover_color = "#447ec9",
height = 40,
width = 130,
font = ("", 15))
# layout for all the modules
frame1.grid(row = 0, column = 0, columnspan = 2, padx = 20, pady = 10)
hinweis_label.grid(row = 0, column = 0, columnspan = 2, padx = 20, pady = 10)
frame2.grid(row = 1, column = 1, columnspan = 2, padx = 20, pady = 5)
frame22.grid(row = 1, column = 0, columnspan = 2, padx = 20, pady = 5)
hinweis2_label.grid(row = 1, column = 0, columnspan = 2, padx = 10, pady = 10)
weight_title.grid(row = 2, column = 0, padx = 10, pady = 10)
weight_entry.grid(row = 2, column = 1, padx = 20, pady = 10)
height_title.grid(row = 3, column = 0, padx = 10, pady = 10)
height_entry.grid(row = 3, column = 1, padx = 20, pady = 10)
converter_button.grid (row = 4, column = 0, columnspan = 2, padx = 10, pady = 10)
frame3.grid(row = 5, column = 0, columnspan = 2, padx = 20, pady = 10)
output_field.grid(row = 5, column = 1, padx = 20, pady = 10)
app.mainloop()