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.

104 lines
4.0 KiB

7 months ago
import tkinter as tk
# import matplotlib.pyplot as plt
# from matplotlib.pyplot import figure
7 months ago
import numpy as np
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
fen = tk.Tk()
home = tk.Frame()
7 months ago
fen.title("Calculateur d'IMC")
7 months ago
#taille de la fenetre
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)
7 months ago
canvas.grid(column=1,row=0) #son placement
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)
7 months ago
canvas2.grid(column=0, row=0) #son placement
lbl1=tk.Label(fen, text="votre poids (en kg)", font='Arial') #label poids
7 months ago
lbl1.grid(column=0, columnspan=2, padx=10, pady=10, row=1)
7 months ago
entree_kg = tk.Entry(fen) #entry poids
7 months ago
entree_kg.grid(column=0, columnspan=2,ipadx=50, padx=10, pady=10, row=2)
7 months ago
lbl2=tk.Label(fen, text="votre taille (en cm)", font='Arial') #label taille
7 months ago
lbl2.grid(column=0, columnspan=2, padx=10, pady=10, row=3)
7 months ago
entree_cm = tk.Entry(fen) #entry taille
7 months ago
entree_cm.grid(column=0, columnspan=2,ipadx=50, padx=10, pady=10, row=4)
7 months ago
Label1=tk.Label(fen, text=" ", font=('Arial'))
Label1.grid(column=1, row=1, sticky="e", padx=50, pady=10)
7 months ago
#photos
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')
7 months ago
7 months ago
#fonction qui affiche image imc+petite phrase
7 months ago
def afficher_imc():
taille = float(entree_cm.get())/100 #convertir cm en m
poids= float(entree_kg.get())
7 months ago
imc =float(poids/taille**2) #calcul imc
if imc <=18.4:
Label1.config(text="Vous êtes en sous-poids")
canvas2.itemconfig(image_container2,image=image_sousp)
7 months ago
if imc >=18.5 and imc<=24.9:
Label1.config(text="Votre poids est normal")
canvas2.itemconfig(image_container2,image=image_norm)
7 months ago
if imc >=25.0 and imc<=29.9:
Label1.config(text="Vous êtes en sur poids")
canvas2.itemconfig(image_container2,image=image_surpoids)
7 months ago
if imc >=30.0 and imc<=34.9:
Label1.config(text="Vous etes en obesité")
canvas2.itemconfig(image_container2,image=image_obes)
7 months ago
if imc >=35.0:
Label1.config(text="Vous etes en obesité sévere")
canvas2.itemconfig(image_container2,image=image_obes_s)
7 months ago
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)
7 months ago
# graphique
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
7 months ago
# cm//m
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
7 months ago
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)
7 months ago
bouton.grid(column=0, columnspan=2,ipadx=50, padx=10, pady=10, row=6)
7 months ago
fen.mainloop()