Browse Source

version final de mon tp

master
Ambre 5 months ago
parent
commit
69af343af2
  1. 37
      tp imc.py

37
tp imc.py

@ -1,9 +1,12 @@
import tkinter as tk
# import matplotlib.pyplot as plt
# from matplotlib.pyplot import figure
from decimal import *
import numpy as np
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
fen = tk.Tk()
home = tk.Frame()
fen.title("Calculateur d'IMC")
@ -12,14 +15,14 @@ fen.title("Calculateur d'IMC")
fen.geometry("950x750")
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
blanc1 = tk.PhotoImage(file = 'blanc1.png')#image cachée
image_container1= canvas.create_image(0, 0,anchor=tk.NW,image = blanc1)#son placement
canvas.grid(column=1,row=0) #placement canvas
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
blanc = tk.PhotoImage(file = 'blanc.png')#image cachée
image_container2= canvas2.create_image(40, 10,anchor=tk.NW, image = blanc)#son placement
canvas2.grid(column=0, row=0) #placement canvas
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)
@ -33,7 +36,7 @@ lbl2.grid(column=0, columnspan=2, padx=10, pady=10, row=3)
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=tk.Label(fen, text=" ", font=('Arial'))#texte de droite caché
Label1.grid(column=1, row=1, sticky="e", padx=50, pady=10)
#photos
@ -45,7 +48,7 @@ image_sousp = tk.PhotoImage(file = 'sous poids.png')
image_surpoids = tk.PhotoImage(file = 'surpoids.png')
#fonction qui affiche image imc+petite phrase
#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())
@ -70,11 +73,14 @@ def afficher_imc():
if imc >=35.0:
Label1.config(text="Vous etes en obesité sévere")
canvas2.itemconfig(image_container2,image=image_obes_s)
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, font='Arial') #afficher le resultat calcul imc
lbl=tk.Label(fen, text=imc_simple, font='Arial') #afficher le resultat calcul imc
lbl.grid(column=0, row=2)
# graphique
@ -88,14 +94,15 @@ def afficher_imc():
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
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=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)

Loading…
Cancel
Save