You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.9 KiB
110 lines
3.9 KiB
from tkinter import *
|
|
import tkinter as tk
|
|
import matplotlib.pyplot as plt
|
|
from matplotlib.pyplot import figure
|
|
import numpy as np
|
|
fen = Tk()
|
|
home = 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.grid(column=1,row=0) #son placement
|
|
|
|
canvas2=Canvas(fen, width=225, height=500, 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, columnspan=2, padx=10, pady=10, row=1)
|
|
|
|
entree_kg = 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.grid(column=0, columnspan=2, padx=10, pady=10, row=3)
|
|
|
|
entree_cm = Entry(fen) #entry taille
|
|
entree_cm.grid(column=0, columnspan=2,ipadx=50, padx=10, pady=10, 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')
|
|
|
|
#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="sous-poids", font=('Arial'))
|
|
text.grid(column=1, row=1, columnspan=12)
|
|
canvas2.create_image(40, 10,anchor=NW, 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, columnspan=12)
|
|
canvas2.create_image(40,10,anchor=NW,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, columnspan=12)
|
|
canvas2.create_image(20, 20,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',))
|
|
text=Label(fen, text="vous etes en obesité", font=('Arial'))
|
|
text.grid(column=1, row=1, columnspan=11)
|
|
canvas2.create_image(10, 10,anchor=NW, image = image_obes)
|
|
|
|
if imc >=35.0:
|
|
lbl=Label(fen, text="vous etes en obesité sévere", font=('Arial'))
|
|
lbl.grid(column=1, row=1, columnspan=11)
|
|
canvas2.create_image(10, 10,anchor=NW, 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)
|
|
|
|
# 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') 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)
|
|
bouton.grid(column=0, columnspan=2,ipadx=50, padx=10, pady=10, row=6)
|
|
|
|
|
|
|
|
fen.mainloop()
|
|
|