1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
   | # -*- coding: utf-8 -*-
 
from tkinter import *
import numpy as np
import matplotlib.pyplot as plt
 
class GUI:
    def __init__(self):
        self.root      = Tk()
        self.labelVariable = StringVar()
        self.root.title('Projet informatique')
        self.initialize()
        self.root.mainloop()
 
    def initialize(self):
        self.main = Frame(self.root)
        self.main.pack() 
 
        label = Label(self.main, textvariable=self.labelVariable, font=('courier',10,'bold'), anchor="w", fg="red", bg="white")
        label.pack()
        self.labelVariable.set("Modelisation de populations atteintes dun virus")
        v=Listbox(self.main)
        v.insert("end","Modele SIR")
        v.insert("end","Modele de Witowski")
        v.insert("end","Modele de Munz")
        v.insert("end","Modele avec traitement")
        v.bind("<Double-Button-1>", self.Double) 
        v.pack(expand=1,fill=BOTH)
 
 
    def Double(self,event):
        widget    = event.widget
        selection = widget.curselection()
        value     = widget.get(selection[0])
        self.newWindow(value)
        return(value)
 
    def ModifyTextarea(self,elem,msg,clear=None):
        elem.config(state=NORMAL)
        if clear:
            elem.delete(1.0, END)
        else:
            elem.insert(END,msg)
        elem.config(state=DISABLED)
    def newWindow(self,msg):
        top = Toplevel(self.root)
        q1 = Frame(top)
        q1.pack()
        top.grab_set()
        text = Text(q1,state=DISABLED,exportselection=True)
        text.pack()
        self.ModifyTextarea(text,msg)
 
        e1=Entry(q1)
        e2=Entry(q1)
        e3=Entry(q1)
        e4=Entry(q1)
        e5=Entry(q1)
        e6=Entry(q1)
        e1.pack()
        e2.pack()
        e3.pack()
        e4.pack()
        e5.pack()
        e6.pack()
 
        def zombies() :
                a=float(e1.get())
                b=float(e2.get())
                ze=float(e3.get())
                T=float(e4.get())
                N=float(e5.get())
                dt=float(e6.get())
                n = T/dt
                n=int(n)
                t=np.zeros((n+1))
                for i in range (0,n):
                    t[0]=0
                    t[i+1]=t[i]+dt
                s = np.zeros((n+1))
                z = np.zeros((n+1))
                r = np.zeros((n+1))
                s[0] = N-1
                z[0] =1
                r[0] = 0
 
                for i in range (n-1):
                    s[i+1] = s[i] + dt*(-b*s[i]*z[i])
                    z[i+1] = z[i] + dt*(b*s[i]*z[i]-a*s[i]*z[i]+ze*r[i])
                    r[i+1] = r[i] + dt*(a*s[i]*z[i]- ze*r[i])
 
                    if s[i+1]<0 or s[i+1] >N:
                        s[i+1]=0
                        break
 
                    if z[i+1] > N or z[i+1] < 0:
                        z[i+1]=0
                        break
 
                    if r[i+1] <0 or r[i+1] >N:
                        r[i+1]=0
                        break
                    return (t,s,r,z,i+2)
 
        btnquit = Button(q1,width = 1,text = "Ok",command =zombies)
        btnquit.pack()
 
 
 
 
        t,s,r,z,i=zombies()
        plt.plot(t[:i],s[:i],'b')
        plt.plot(t[:i],z[:i],'r')
        plt.plot(t[:i],r[:i],'y')
        plt.show()
 
if __name__ == "__main__":
    app = GUI() | 
Partager