-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
61 lines (48 loc) · 1.43 KB
/
script.py
File metadata and controls
61 lines (48 loc) · 1.43 KB
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
#coding:utf-8
import tkinter
from tkinter import messagebox
def imc(mass, height):
imc = mass/(height*height)
if imc < 18.5:
return "Underweight"
elif 18.5 <= imc < 25:
return "Normal"
elif 25 <= imc < 30:
return "Overweight"
elif 30 <= imc < 35:
return "Obese"
else:
return "Extremley Obese"
def buttonFct():
if not is_number(entMass.get()) or not is_number(entHeight.get()):
messagebox.showerror("ERROR","You did not enter the correct values !")
else:
labRep.config(text=f"{imc(float(entMass.get()),float(entHeight.get()))}")
def is_number(s):
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False
app = tkinter.Tk()
app.geometry("300x260")
labMass = tkinter.Label(app, text="Weight(kg)", font=("Courier", 24))
labMass.place(x=5, y=0)
entMass = tkinter.Entry(app, width=20)
entMass.place(x=5, y=50)
labHeight = tkinter.Label(app, text="Size(m)", font=("Courier", 24))
labHeight.place(x=5, y=75)
entHeight = tkinter.Entry(app, width=20)
entHeight.place(x=5, y=125)
but = tkinter.Button(app, text="Result", command=buttonFct, font=("Courier", 16))
but.place(x=5, y=160)
labRep = tkinter.Label(app, text="Response", font=("Courier", 24))
labRep.place(x=5, y=210)
app.mainloop()