Hello everyone,
I would like to model the evolution of a disease thanks to python by representing this evolution thanks to man logos that change colors (several images). All this in a frame with tkinter. Despite everything several problems arise including one in particular. I can not display a number of images corresponding to for example the number of sick people on such a day and then change that number there. (For precision: I obviously download the images). For now this is what my code looks like with helpers that I could find everywhere on the internet:
#Télécharger PILLOW PIL dans les outils
from tkinter import *
from tkinter import ttk
from PIL import Image, ImageTk
def SJHD(vecteurdedonnees,t,N,tauxmortalité,tauxvaccination,tauxcontamination,tauxhospitalisation,tauxdeces):
S,J,H,D = vecteurdedonnees
dSdt=tauxmortalité*(N-S)-tauxcontamination*((SH)/N)-tauxvaccinationS
dJdt=tauxcontamination*((SH)/N)-(tauxmortalité+tauxhospitalisation)J
dHdt=(tauxhospitalisationJ)-(tauxmortalité+tauxdeces)H
dDdt=(tauxdecesH)+tauxmortalitéD+tauxvaccination*S
return dSdt, dJdt, dHdt, dDdt
root = Tk()
root.title(“Pneumatite”)
root.config(bg=“grey”)
root.geometry(“640x480”)
mainframe = ttk.Frame(root, padding=“10 20 10 20”)
mainframe.grid()
ttk.Label(mainframe, text="Nombre total : ").grid(column=1, row=0, sticky=(W,))
ttk.Label(mainframe, text=“Nombre de malades ?”).grid(column=1, row=1, sticky=(W,))
ttk.Label(mainframe, text="300 ").grid(column=2, row=0, sticky=(N,))
button = ttk.Button(mainframe, text=“Cliquer”,command=SJHD)
button.grid(column=2, row=2, sticky=(W), padx=60, pady=60)
malades = StringVar()
malades_entry = ttk.Entry(mainframe, width=7, textvariable=malades)
malades_entry.grid(column=2, row=1, padx=5, pady=5)
#Télécharger les fichiers joints dans le même dossier que pneumatite.py
img1_pil = Image.open(‘monimage.png’)
mainframe = ttk.Frame(root, padding=“10 20 10 20”)
mainframe.grid(row=2)
for colonne in range(50):
for rang in range(6):
img1_pil.thumbnail((15,15), Image.LANCZOS)
img1 = ImageTk.PhotoImage(img1_pil)
label = ttk.Label(mainframe, image=img1)
label.image = img1
label.grid(column=colonne, row=rang)
N=300
tauxmortalité=0
tauxvaccination=1/100
tauxcontamination=1/3
tauxhospitalisation=1/9
tauxdeces=1/27
nombrejoursdesimu = 30
J0=input(malades.get())
H0=0
D0=0
S0=N-J0-H0-D0
#Télécharger scipy, matplotlib, numpy dans les outils
from scipy.integrate import odeint
import numpy as np
vecteurTemporel=np.linspace(0,nombrejoursdesimu,nombrejoursdesimu)
datas=np.array([S0,J0,H0,D0])
solutions=odeint(SJHD,
datas,
vecteurTemporel,
args=(N,tauxmortalité,tauxvaccination,tauxcontamination,tauxhospitalisation,tauxdeces))
S,J,H,D = solutions.T
S
int(S.get())
import matplotlib.image as mpimg
import numpy as np
img2= mgimg.imread(“monimage.png”)
if img2.dtype == np.float32 :
img2= (img2*255).astype(np.uint8)
int(J.get())
import matplotlib.image as mpimg
import numpy as np
img3= mgimg.imread(“jaune.png”)
if img3.dtype == np.float32 :
img3= (img3*255).astype(np.uint8)
int(H.get())
import matplotlib.image as mpimg
import numpy as np
img4= mgimg.imread(“orange.png”)
if img4.dtype == np.float32 :
img4= (img4*255).astype(np.uint8)
int(D.get())
import matplotlib.image as mpimg
import numpy as np
img5= mgimg.imread(“rouge.png”)
if img5.dtype == np.float32 :
img5= (img5*255).astype(np.uint8)
root.mainloop()
Thank you very much to the people who could help me with that.
P.S. It is rather urgent unfortunately, a little last hope.