|
|
@ -1,113 +1,101 @@ |
|
|
|
from tkinter import * |
|
|
|
import tkinter as tk |
|
|
|
import matplotlib.pyplot as plt |
|
|
|
from matplotlib.pyplot import figure |
|
|
|
# import matplotlib.pyplot as plt |
|
|
|
# from matplotlib.pyplot import figure |
|
|
|
import numpy as np |
|
|
|
from matplotlib.figure import Figure |
|
|
|
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg |
|
|
|
fen = Tk() |
|
|
|
home = Frame() |
|
|
|
fen = tk.Tk() |
|
|
|
home = tk.Frame() |
|
|
|
fen.title("Calculateur d'IMC") |
|
|
|
|
|
|
|
#taille de la fenetre |
|
|
|
fen.geometry("950x750") |
|
|
|
|
|
|
|
#image en fond |
|
|
|
#bg = PhotoImage(file = "fondec.png") |
|
|
|
#label1 = Label(fen, image = bg) |
|
|
|
#label1.place(x = 0, y = 0) |
|
|
|
|
|
|
|
#couleur de fond du canvas |
|
|
|
#fen.configure(bg="red") |
|
|
|
|
|
|
|
|
|
|
|
canvas=Canvas(fen, width=600, height=500, bg="blue") #canvas de droite |
|
|
|
canvas=tk.Canvas(fen, width=600, height=500, bg="white") #canvas de droite |
|
|
|
blanc1 = tk.PhotoImage(file = 'blanc1.png') |
|
|
|
image_container1= canvas.create_image(0, 0,anchor=tk.NW,image = blanc1) |
|
|
|
canvas.grid(column=1,row=0) #son placement |
|
|
|
|
|
|
|
canvas2=Canvas(fen, width=225, height=500, bg="white") #canvas de gauche |
|
|
|
canvas2=tk.Canvas(fen, width=225, height=500, bg="white") #canvas de gauche |
|
|
|
blanc = tk.PhotoImage(file = 'blanc.png') |
|
|
|
image_container2= canvas2.create_image(40, 10,anchor=tk.NW, image = blanc) |
|
|
|
canvas2.grid(column=0, row=0) #son placement |
|
|
|
|
|
|
|
lbl1=Label(fen, text="votre poids (en kg)", font='Arial') #label poids |
|
|
|
lbl1=tk.Label(fen, text="votre poids (en kg)", font='Arial') #label poids |
|
|
|
lbl1.grid(column=0, columnspan=2, padx=10, pady=10, row=1) |
|
|
|
|
|
|
|
entree_kg = Entry(fen) #entry poids |
|
|
|
entree_kg = tk.Entry(fen) #entry poids |
|
|
|
entree_kg.grid(column=0, columnspan=2,ipadx=50, padx=10, pady=10, row=2) |
|
|
|
|
|
|
|
lbl2=Label(fen, text="votre taille (en cm)", font='Arial') #label taille |
|
|
|
lbl2=tk.Label(fen, text="votre taille (en cm)", font='Arial') #label taille |
|
|
|
lbl2.grid(column=0, columnspan=2, padx=10, pady=10, row=3) |
|
|
|
|
|
|
|
entree_cm = Entry(fen) #entry taille |
|
|
|
entree_cm = tk.Entry(fen) #entry taille |
|
|
|
entree_cm.grid(column=0, columnspan=2,ipadx=50, padx=10, pady=10, row=4) |
|
|
|
|
|
|
|
Label1=tk.Label(fen, text=" ", font=('Arial')) |
|
|
|
Label1.grid(column=1, row=1, sticky="e", padx=50, pady=10) |
|
|
|
|
|
|
|
#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') |
|
|
|
image_norm = tk.PhotoImage(file = 'normal.png') |
|
|
|
image_obes_s = tk.PhotoImage(file = 'obesite severe.png') |
|
|
|
image_obes = tk.PhotoImage(file = 'obesite.png') |
|
|
|
image_sousp = tk.PhotoImage(file = 'sous poids.png') |
|
|
|
image_surpoids = tk.PhotoImage(file = 'surpoids.png') |
|
|
|
|
|
|
|
|
|
|
|
#fonction qui affiche image imc+petite phrase |
|
|
|
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=Label(fen, text="Vous êtes en sous-poids", font=('Arial')) |
|
|
|
text.grid(column=1, row=1, sticky="e", padx=10, pady=10) |
|
|
|
canvas2.create_image(40, 10,anchor=NW, image = image_sousp) |
|
|
|
Label1.config(text="Vous êtes en sous-poids") |
|
|
|
canvas2.itemconfig(image_container2,image=image_sousp) |
|
|
|
|
|
|
|
if imc >=18.5 and imc<=24.9: |
|
|
|
text=Label(fen, text="Votre poids est normal", font=('Arial')) |
|
|
|
text.grid(column=1, row=1, sticky="e", padx=10, pady=10) |
|
|
|
canvas2.create_image(40,10,anchor=NW,image=image_norm) |
|
|
|
Label1.config(text="Votre poids est normal") |
|
|
|
canvas2.itemconfig(image_container2,image=image_norm) |
|
|
|
|
|
|
|
if imc >=25.0 and imc<=29.9: |
|
|
|
text=Label(fen, text="Vous êtes en sur poids", font=('Arial')) |
|
|
|
text.grid(column=1, row=1, sticky="e", padx=10, pady=10) |
|
|
|
canvas2.create_image(20, 20,anchor=NW, image = image_surpoids) |
|
|
|
Label1.config(text="Vous êtes en sur poids") |
|
|
|
canvas2.itemconfig(image_container2,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',)) |
|
|
|
text=Label(fen, text="Vous etes en obesité", font=('Arial')) |
|
|
|
text.grid(column=1, row=1, sticky="e", padx=10, pady=10) |
|
|
|
canvas2.create_image(10, 10,anchor=NW, image = image_obes) |
|
|
|
Label1.config(text="Vous etes en obesité") |
|
|
|
canvas2.itemconfig(image_container2,image=image_obes) |
|
|
|
|
|
|
|
if imc >=35.0: |
|
|
|
text=Label(fen, text="Vous etes en obesité sévere", font=('Arial')) |
|
|
|
text.grid(column=1, row=1, sticky="e", padx=10, pady=10) |
|
|
|
canvas2.create_image(10, 10,anchor=NW, image = image_obes_s) |
|
|
|
if imc >=35.0: |
|
|
|
Label1.config(text="Vous etes en obesité sévere") |
|
|
|
canvas2.itemconfig(image_container2,image=image_obes_s) |
|
|
|
|
|
|
|
lbl=Label(fen, text="Votre imc est de :", font='Arial') |
|
|
|
lbl.grid(column=0,row=1) |
|
|
|
lbl=Label(fen, text=imc, font='Arial') #afficher le resultat calcul imc |
|
|
|
lbl.grid(column=0, row=2) |
|
|
|
lbl=tk.Label(fen, text="Votre imc est de :", font='Arial') |
|
|
|
lbl.grid(column=0,row=1) |
|
|
|
lbl=tk.Label(fen, text=imc, font='Arial') #afficher le resultat calcul imc |
|
|
|
lbl.grid(column=0, row=2) |
|
|
|
|
|
|
|
# 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 |
|
|
|
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 |
|
|
|
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, 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 |
|
|
|
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 |
|
|
|
|
|
|
|
plt.xlabel('Taille (cm)') |
|
|
|
plt.ylabel('Poids (kg)') |
|
|
|
plt.title('IMC') |
|
|
|
plt.show() |
|
|
|
|
|
|
|
bouton=Button(fen, text="Afficher l'IMC", command=afficher_imc) |
|
|
|
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.grid(column=0, columnspan=2,ipadx=50, padx=10, pady=10, row=6) |
|
|
|
|
|
|
|
|
|
|
|