Browse Source

version presque finale, plus que le graph

master
Ambre 7 months ago
parent
commit
6aa3cc89b0
  1. 35
      tp imc.py

35
tp imc.py

@ -3,6 +3,8 @@ import tkinter as tk
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib.pyplot import figure from matplotlib.pyplot import figure
import numpy as np import numpy as np
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
fen = Tk() fen = Tk()
home = Frame() home = Frame()
fen.title("Calculateur d'IMC") fen.title("Calculateur d'IMC")
@ -52,32 +54,32 @@ def afficher_imc():
imc =float(poids/taille**2) #calcul imc imc =float(poids/taille**2) #calcul imc
if imc <=18.4: if imc <=18.4:
text=Label(fen, text="sous-poids", font=('Arial')) text=Label(fen, text="Vous êtes en sous-poids", font=('Arial'))
text.grid(column=1, row=1, columnspan=12) text.grid(column=1, row=1, sticky="e", padx=10, pady=10)
canvas2.create_image(40, 10,anchor=NW, image = image_sousp) canvas2.create_image(40, 10,anchor=NW, image = image_sousp)
if imc >=18.5 and imc<=24.9: if imc >=18.5 and imc<=24.9:
text=Label(fen, text="votre poids est normal", font=('Arial')) text=Label(fen, text="Votre poids est normal", font=('Arial'))
text.grid(column=1, row=1, columnspan=12) text.grid(column=1, row=1, sticky="e", padx=10, pady=10)
canvas2.create_image(40,10,anchor=NW,image=image_norm) canvas2.create_image(40,10,anchor=NW,image=image_norm)
if imc >=25.0 and imc<=29.9: if imc >=25.0 and imc<=29.9:
text=Label(fen, text="vous êtes en sur poids", font=('Arial')) text=Label(fen, text="Vous êtes en sur poids", font=('Arial'))
text.grid(column=1, row=1, columnspan=12) text.grid(column=1, row=1, sticky="e", padx=10, pady=10)
canvas2.create_image(20, 20,anchor=NW, image = image_surpoids) canvas2.create_image(20, 20,anchor=NW, image = image_surpoids)
if imc >=30.0 and imc<=34.9: if imc >=30.0 and imc<=34.9:
#text= canvas.create_text(200,40,text="vous etes en obesité", font=('Helvetica','30',)) #text= canvas.create_text(200,40,text="vous etes en obesité", font=('Helvetica','30',))
text=Label(fen, text="vous etes en obesité", font=('Arial')) text=Label(fen, text="Vous etes en obesité", font=('Arial'))
text.grid(column=1, row=1, columnspan=11) text.grid(column=1, row=1, sticky="e", padx=10, pady=10)
canvas2.create_image(10, 10,anchor=NW, image = image_obes) canvas2.create_image(10, 10,anchor=NW, image = image_obes)
if imc >=35.0: if imc >=35.0:
lbl=Label(fen, text="vous etes en obesité sévere", font=('Arial')) text=Label(fen, text="Vous etes en obesité sévere", font=('Arial'))
lbl.grid(column=1, row=1, columnspan=11) text.grid(column=1, row=1, sticky="e", padx=10, pady=10)
canvas2.create_image(10, 10,anchor=NW, image = image_obes_s) canvas2.create_image(10, 10,anchor=NW, image = image_obes_s)
lbl=Label(fen, text="votre imc est de :", font='Arial') lbl=Label(fen, text="Votre imc est de :", font='Arial')
lbl.grid(column=0,row=1) lbl.grid(column=0,row=1)
lbl=Label(fen, text=imc, font='Arial') #afficher le resultat calcul imc lbl=Label(fen, text=imc, font='Arial') #afficher le resultat calcul imc
lbl.grid(column=0, row=2) lbl.grid(column=0, row=2)
@ -88,18 +90,21 @@ def afficher_imc():
fig=new_manager.canvas.figure fig=new_manager.canvas.figure
fig.set_canvas(new_manager.canvas) fig.set_canvas(new_manager.canvas)
x = np.linspace(100, 220) # les tailles extrèmes en cm x = np.linspace(100, 220) # les tailles extrèmes en cm
# cm//m # cm//m
plt.fill_between(x, 0, 18.5 * (x/100)**2, label="sous poids",color="LightBlue") # sous poids si 0 <= y <= 18.5 * x² plt.fill_between(x, 0, 18.4 * (x/100)**2, label="sous poids",color="LightBlue") # sous poids si 0 <= y <= 18.4 * x²
plt.fill_between(x, 18.5 * (x/100)**2, 25 * (x/100)**2, label="poids idéal",color="yellow") # idéal si 18.5 * x² <= y <= 25 * x² plt.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²
plt.fill_between(x, 25 * (x/100)**2, 29.9 * (x/100)**2, label="surpoids",color="yellow") # surpoids si 25 * x² <= y <= 29.9 * x²
plt.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²
#plt.fill_between(x, 35 * (x/100)**2, 80 * (x/100)**2, label="obesité sévère",color="red") # obesité sevère si 35 * x² <= y
#plt.scatter(entree_cm.get(), poids, color='gray') point a placer sur le graphique #plt.scatter(entree_cm.get(), poids, color='gray') point a placer sur le graphique
plt.xlabel('Taille (cm)') plt.xlabel('Taille (cm)')
plt.ylabel('Poids (kg)') plt.ylabel('Poids (kg)')
plt.title('IMC') plt.title('IMC')
plt.show() plt.show()
bouton=Button(fen, text="Afficher l'IMC", command=afficher_imc) bouton=Button(fen, text="Afficher l'IMC", command=afficher_imc)

Loading…
Cancel
Save