diff --git a/tp imc.py b/tp imc.py index 45fd385..c7e0411 100644 --- a/tp imc.py +++ b/tp imc.py @@ -50,57 +50,70 @@ image_surpoids = tk.PhotoImage(file = 'surpoids.png') #fonction qui affiche image imc+petite phrase+graphique def afficher_imc(): - taille = float(entree_cm.get())/100 #convertir cm en m - poids= float(entree_kg.get()) - - imc =float(poids/taille**2) #calcul imc - - if imc <=18.4: - Label1.config(text="Vous êtes en sous-poids") - canvas2.itemconfig(image_container2,image=image_sousp) + if float(entree_cm.get()) < 100: + Label1.config(text="Veuillez entrer une valeur plus haute(cm)") + + elif float(entree_cm.get()) > 210: + Label1.config(text="Veuillez entrer une valeur plus basse(cm)") - if imc >=18.5 and imc<=24.9: - Label1.config(text="Votre poids est normal") - canvas2.itemconfig(image_container2,image=image_norm) + elif float(entree_kg.get()) <= 0: + Label1.config(text="Veuillez entrer une valeur plus basse(kg)") - if imc >=25.0 and imc<=29.9: - Label1.config(text="Vous êtes en sur poids") - canvas2.itemconfig(image_container2,image=image_surpoids) + elif float(entree_kg.get()) > 210: + Label1.config(text="Veuillez entrer une valeur plus haute(kg)") - if imc >=30.0 and imc<=34.9: - Label1.config(text="Vous etes en obesité") - canvas2.itemconfig(image_container2,image=image_obes) + else: + taille = float(entree_cm.get())/100 #convertir cm en m + poids= float(entree_kg.get()) - if imc >=35.0: - Label1.config(text="Vous etes en obesité sévere") - canvas2.itemconfig(image_container2, image=image_obes_s)#l'image de l'obésité sévère est un peu décalée, - #je ne suis pas arrivé à la redimensionner - imc2=Decimal(imc) - imc_simple = imc2.quantize(Decimal('.01')) #deux chiffres après la virgule - - lbl=tk.Label(fen, text="Votre imc est de :", font='Arial') - lbl.grid(column=0,row=1) - lbl=tk.Label(fen, text=imc_simple, font='Arial') #afficher le resultat calcul imc - lbl.grid(column=0, row=2) - - # graphique - fig = Figure(figsize=(7.2, 5.2), dpi=96) - ax = fig.add_subplot(111) - ax.axis([100, 220, 0, 180]) #limite du graphe - x = np.linspace(100, 220) # les tailles extrèmes en cm - # cm//m - ax.fill_between(x, 0, 18.4 * (x/100)**2, label="sous poids",color="LightBlue") # sous poids si 0 <= y <= 18.4 * x² - ax.fill_between(x, 18.5 * (x/100)**2, 24.9 * (x/100)**2, label="poids idéal",color="green") # idéal si 18.5 * x² <= y <= 24.9 * x² - ax.fill_between(x, 25 * (x/100)**2, 29.9 * (x/100)**2, label="surpoids",color="yellow") # surpoids si 25 * x² <= y <= 29.9 * x² - ax.fill_between(x, 30 * (x/100)**2, 34.9 * (x/100)**2, label="obesité",color="orange") # obésité si 30 * x² <= y <= 34.9 * x² - ax.fill_between(x,180, 35 * (x/100)**2, 40 * (x/100)**2, label="obesité sévère",color="red") # obesité sevère si 35 * x² <= y - ax.scatter(taille*100, poids, color='black')#point a placer sur le graphique. il ne s'affiche qu'une fois - #parce que je ne suis pas arrivé a ne pas le réinitialisé - - - graph = FigureCanvasTkAgg(fig, master=fen) - canvas = graph.get_tk_widget() - canvas.grid(row=0, column=1) + imc =float(poids/taille**2) #calcul imc + + if imc <=18.4: + Label1.config(text="Vous êtes en sous-poids") + canvas2.itemconfig(image_container2,image=image_sousp) + + if imc >=18.5 and imc<=24.9: + Label1.config(text="Votre poids est normal") + canvas2.itemconfig(image_container2,image=image_norm) + + if imc >=25.0 and imc<=29.9: + Label1.config(text="Vous êtes en sur poids") + canvas2.itemconfig(image_container2,image=image_surpoids) + + if imc >=30.0 and imc<=34.9: + Label1.config(text="Vous etes en obesité") + canvas2.itemconfig(image_container2,image=image_obes) + + if imc >=35.0: + Label1.config(text="Vous etes en obesité sévere") + canvas2.itemconfig(image_container2, image=image_obes_s)#l'image de l'obésité sévère est un peu décalée, + #je ne suis pas arrivé à la redimensionner + imc2=Decimal(imc) + imc_simple = imc2.quantize(Decimal('.01')) #deux chiffres après la virgule + + lbl=tk.Label(fen, text="Votre imc est de :", font='Arial') + lbl.grid(column=0,row=1) + lbl=tk.Label(fen, text=imc_simple, font='Arial') #afficher le resultat calcul imc + lbl.grid(column=0, row=2) + + # graphique + fig = Figure(figsize=(7.2, 5.2), dpi=96) + ax = fig.add_subplot(111) + ax.axis([100, 220, 0, 180]) #limite du graphe + x = np.linspace(100, 220) # les tailles extrèmes en cm + # cm//m + ax.fill_between(x, 0, 18.4 * (x/100)**2, label="sous poids",color="LightBlue") # sous poids si 0 <= y <= 18.4 * x² + ax.fill_between(x, 18.5 * (x/100)**2, 24.9 * (x/100)**2, label="poids idéal",color="green") # idéal si 18.5 * x² <= y <= 24.9 * x² + ax.fill_between(x, 25 * (x/100)**2, 29.9 * (x/100)**2, label="surpoids",color="yellow") # surpoids si 25 * x² <= y <= 29.9 * x² + ax.fill_between(x, 30 * (x/100)**2, 34.9 * (x/100)**2, label="obesité",color="orange") # obésité si 30 * x² <= y <= 34.9 * x² + ax.fill_between(x,180, 35 * (x/100)**2, 40 * (x/100)**2, label="obesité sévère",color="red") # obesité sevère si 35 * x² <= y + ax.scatter(taille*100, poids, color='black')#point a placer sur le graphique. il ne s'affiche qu'une fois + #parce que je ne suis pas arrivé a ne pas le réinitialisé + + + graph = FigureCanvasTkAgg(fig, master=fen) + canvas = graph.get_tk_widget() + canvas.grid(row=0, column=1) bouton=tk.Button(fen, text="Afficher l'IMC", command=afficher_imc) #bouton pour afficher tout bouton.grid(column=0, columnspan=2,ipadx=50, padx=10, pady=10, row=6)