commit 3ac3d034b8ae60b687c559a653051249e520b577 Author: ambre <> Date: Mon Apr 29 11:22:59 2024 +0200 first commit diff --git a/exemple_configure.py b/exemple_configure.py new file mode 100644 index 0000000..b2ae7be --- /dev/null +++ b/exemple_configure.py @@ -0,0 +1,22 @@ +import tkinter as tk +import matplotlib.pyplot as plt + +def modif(): + x = float(entry.get()) + lbl.configure(text="x vaut "+str(x)) + plt.scatter(x, x) + plt.show() + +fen = tk.Tk() +lbl = tk.Label(fen, text="Le texte initial") +lbl.grid() +entry = tk.Entry() +entry.grid() +b1 = tk.Button(fen, text="bouton 1", command=modif) +b1.grid() + +fig = plt.figure() +plt.xlim(-5,5) +plt.ylim(-5,5) + +fen.mainloop() diff --git a/exemple_fill.py b/exemple_fill.py new file mode 100644 index 0000000..ab049d7 --- /dev/null +++ b/exemple_fill.py @@ -0,0 +1,13 @@ +import matplotlib.pyplot as plt +import numpy as np + +x = np.linspace(100, 220) # les tailles extrèmes en cm +# Attention, x est en cm, mais les calculs se font avec x en 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.xlabel('Taille (cm)') +plt.ylabel('Poids (kg)') +plt.title('IMC') +plt.legend() +plt.show() \ No newline at end of file diff --git a/normal.png b/normal.png new file mode 100644 index 0000000..b1a7687 Binary files /dev/null and b/normal.png differ diff --git a/obesite severe.png b/obesite severe.png new file mode 100644 index 0000000..f86fe74 Binary files /dev/null and b/obesite severe.png differ diff --git a/obesite.png b/obesite.png new file mode 100644 index 0000000..637b3fd Binary files /dev/null and b/obesite.png differ diff --git a/sous poids.png b/sous poids.png new file mode 100644 index 0000000..f82cefb Binary files /dev/null and b/sous poids.png differ diff --git a/surpoids.png b/surpoids.png new file mode 100644 index 0000000..7e60b49 Binary files /dev/null and b/surpoids.png differ diff --git a/tp imc.py b/tp imc.py new file mode 100644 index 0000000..e4f4557 --- /dev/null +++ b/tp imc.py @@ -0,0 +1,90 @@ +from tkinter import * +import matplotlib.pyplot as plt +from matplotlib.pyplot import figure +import numpy as np +fen = Tk() +home = Frame() +fen.title("Calculateur d'IMC") + +canvas=Canvas(fen, width=600, height=400, bg="white") #canvas de droite +canvas.grid(column=1,row=0) #son placement + +canvas2=Canvas(fen, width=150, height=400, 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, row=1) + +entree_kg = Entry(fen) #entry poids +entree_kg.grid(column=0, row=2) + +lbl2=Label(fen, text="votre taille (en cm)", font='Arial') #label taille +lbl2.grid(column=0, row=3) + +entree_cm = Entry(fen) #entry taille +entree_cm.grid(column=0, 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') + + +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= canvas.create_text(200,40,anchor='center',text="vous etes en sous-poids", font=('Helvetica','30')) + canvas2.create_image(10, 10,anchor=NW, image = image_sousp) + + if imc >=18.5 and imc<=24.9: + text= canvas.create_text(200,40,text="votre poids est normal", font=('Helvetica','30',)) + canvas2.create_image(0,0,anchor=NW,image=image_norm) + + if imc >=25.0 and imc<=29.9: + text= canvas.create_text(200,40,text="vous êtes en sur poids", font=('Helvetica','30',)) + canvas2.create_image(0, 0,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',)) + canvas2.create_image(0, 0,anchor=NW, image = image_obes) + + if imc >=35.0: + text= canvas.create_text(200,40,text="vous etes en obesité sévère", font=('Helvetica','30',)) + canvas2.create_image(0, 0,anchor=NW, image = image_obes_s) + + lbl=Label(fen, text="votre imc est de :", font='Arial') + lbl.grid(padx=15, pady=15) + lbl=Label(fen, text=imc, font='Arial') #afficher le resultat calcul imc + lbl.grid(padx=15, pady=15) + # 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') + + 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(padx=50, pady=10) + + + +fen.mainloop()