from tkinter import * import matplotlib.pyplot as plt from matplotlib.pyplot import figure import numpy as np fen = Tk() home = Frame() fen.title("Calculateur d'IMC") canvas=Canvas(fen, width=600, height=400, bg="white") #canvas de droite canvas.grid(column=1,row=0) #son placement canvas2=Canvas(fen, width=150, height=400, bg="white") #canvas de gauche canvas2.grid(column=0, row=0) #son placement lbl1=Label(fen, text="votre poids (en kg)", font='Arial') #label poids lbl1.grid(column=0, row=1) entree_kg = Entry(fen) #entry poids entree_kg.grid(column=0, row=2) lbl2=Label(fen, text="votre taille (en cm)", font='Arial') #label taille lbl2.grid(column=0, row=3) entree_cm = Entry(fen) #entry taille entree_cm.grid(column=0, row=4) #photos image_norm = PhotoImage(file = 'normal.png') image_obes_s = PhotoImage(file = 'obesite severe.png') image_obes = PhotoImage(file = 'obesite.png') image_sousp = PhotoImage(file = 'sous poids.png') image_surpoids = PhotoImage(file = 'surpoids.png') 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: text= canvas.create_text(200,40,anchor='center',text="vous etes en sous-poids", font=('Helvetica','30')) canvas2.create_image(10, 10,anchor=NW, image = image_sousp) if imc >=18.5 and imc<=24.9: text= canvas.create_text(200,40,text="votre poids est normal", font=('Helvetica','30',)) canvas2.create_image(0,0,anchor=NW,image=image_norm) if imc >=25.0 and imc<=29.9: text= canvas.create_text(200,40,text="vous êtes en sur poids", font=('Helvetica','30',)) canvas2.create_image(0, 0,anchor=NW, image = image_surpoids) if imc >=30.0 and imc<=34.9: text= canvas.create_text(200,40,text="vous etes en obesité", font=('Helvetica','30',)) canvas2.create_image(0, 0,anchor=NW, image = image_obes) if imc >=35.0: text= canvas.create_text(200,40,text="vous etes en obesité sévère", font=('Helvetica','30',)) canvas2.create_image(0, 0,anchor=NW, image = image_obes_s) lbl=Label(fen, text="votre imc est de :", font='Arial') lbl.grid(padx=15, pady=15) lbl=Label(fen, text=imc, font='Arial') #afficher le resultat calcul imc lbl.grid(padx=15, pady=15) # graphique new_manager = plt.figure().canvas.manager fig=new_manager.canvas.figure fig.set_canvas(new_manager.canvas) x = np.linspace(100, 220) # les tailles extrèmes en cm # 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, 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.scatter(entree_cm.get(), poids, color='gray') plt.xlabel('Taille (cm)') plt.ylabel('Poids (kg)') plt.title('IMC') plt.show() bouton=Button(fen, text="Afficher l'IMC", command=afficher_imc) bouton.grid(padx=50, pady=10) fen.mainloop()