c'est le sujet 8 du tp tkinter.
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.

116 lines
4.5 KiB

5 months ago
from tkinter import *
5 months ago
import tkinter as tk
5 months ago
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
5 months ago
fen = Tk()
home = Frame()
fen.title("Calculateur d'IMC")
5 months ago
#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
5 months ago
canvas.grid(column=1,row=0) #son placement
5 months ago
canvas2=Canvas(fen, width=225, height=500, bg="white") #canvas de gauche
5 months ago
canvas2.grid(column=0, row=0) #son placement
lbl1=Label(fen, text="votre poids (en kg)", font='Arial') #label poids
5 months ago
lbl1.grid(column=0, columnspan=2, padx=10, pady=10, row=1)
5 months ago
entree_kg = Entry(fen) #entry poids
5 months ago
entree_kg.grid(column=0, columnspan=2,ipadx=50, padx=10, pady=10, row=2)
5 months ago
lbl2=Label(fen, text="votre taille (en cm)", font='Arial') #label taille
5 months ago
lbl2.grid(column=0, columnspan=2, padx=10, pady=10, row=3)
5 months ago
entree_cm = Entry(fen) #entry taille
5 months ago
entree_cm.grid(column=0, columnspan=2,ipadx=50, padx=10, pady=10, row=4)
5 months ago
#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')
5 months ago
#fonction qui affiche image imc+petite phrase
5 months ago
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)
5 months ago
canvas2.create_image(40, 10,anchor=NW, image = image_sousp)
5 months ago
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)
5 months ago
canvas2.create_image(40,10,anchor=NW,image=image_norm)
5 months ago
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)
5 months ago
canvas2.create_image(20, 20,anchor=NW, image = image_surpoids)
5 months ago
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)
5 months ago
canvas2.create_image(10, 10,anchor=NW, image = image_obes)
5 months ago
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)
5 months ago
canvas2.create_image(10, 10,anchor=NW, image = image_obes_s)
5 months ago
lbl=Label(fen, text="Votre imc est de :", font='Arial')
lbl.grid(column=0,row=1)
5 months ago
lbl=Label(fen, text=imc, font='Arial') #afficher le resultat calcul imc
5 months ago
lbl.grid(column=0, row=2)
# graphique
5 months ago
new_manager = plt.figure().canvas.manager
5 months ago
fig=new_manager.canvas.figure
fig.set_canvas(new_manager.canvas)
5 months ago
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
5 months ago
5 months ago
#plt.scatter(entree_cm.get(), poids, color='gray') point a placer sur le graphique
5 months ago
plt.xlabel('Taille (cm)')
plt.ylabel('Poids (kg)')
plt.title('IMC')
plt.show()
bouton=Button(fen, text="Afficher l'IMC", command=afficher_imc)
5 months ago
bouton.grid(column=0, columnspan=2,ipadx=50, padx=10, pady=10, row=6)
5 months ago
fen.mainloop()