Bonjour tout le monde, je me permets de vous contacter pour demander de l'aide. Voilà je réalise un programme de jeu de la vie sur Tkinter que j'essaie de rendre automatique, c'est-à-dire que lorsque j'appuie sur jouer que le jeu évolue tout seul mais voilà pour faire ça j'ai utilisé une boucle while mais lorsque j'appuie sur jouer le jeu plante, est-ce que vous pourriez m'aider?

Concept du jeu de la vie :

Le jeu de la vie a été imaginé par John Horton Conway en 1970.
Il est qualifié de jeu à zéro joueur car il ne nécessite pas l’intervention d’un joueur pendant son déroulement.
Le jeu est représenté par une grille régulière de cellules contenant chacune un état qui est déterminé grâce à la couleur de la cellule.
Exemple : ici, quand une cellule est vivante, elle apparaît avec la couleur Jaune et quand elle est sans vie, elle apparaît en Noir.
Le quadrillage de cellules évolue en fonction du temps, les cellules vivantes à la génération G seront soit vivante soit morte à la génération G+1 selon des conditions spécifiques.
De plus, certaines cellules sans vie à la génération G pourront vivre ou rester dans le même état a la génération G+1 grâce aux mêmes conditions.
Le jeu ne possède pas de but précis mais nous permet d’observer l’évolution des cellules au cours du temps.

Règles du Jeu :

Vous débutez le jeu avec un quadrillage où aucune cellule n’est vivante.
Vous pouvez cliquer les cellules de votre choix pour leur donner vie à la génération 0.
Dans le jeu, une cellule a 8 voisins car chacune d’elles se situent au centre d’un petit quadrillage de 9 cellules. Une fois que votre génération 0 est fixé, Vous pouvez appuyer sur le bouton Départ.
À chaque générations, l’évolution d’une cellule est entièrement déterminée par l’état de ses huit voisines de la façon suivante.
A la génération suivante (génération +1) votre automate cellulaire va évoluer :
- une cellule morte possédant exactement trois voisines vivantes devient vivante (elle naît)
- une cellule vivante possédant seulement deux ou trois voisines vivantes le reste, sinon elle meurt.
Les générations se succèdent jusqu'à ce vos cellules donnent une forme stable où elles seront bloquées a reproduire les même formes en continu.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
from tkinter import *
window= Tk()
window.title("Jeux de la vie")
window.geometry("600x600")
window.minsize(150,150)
window.maxsize(800,800)
window.config(background='white')
frame=Frame(window,bg="white")
table=[[0] * 15 for i in range(15)]
table1=table
tablevie=[[0] * 15 for i in range(15)]
 
 
file=open("regles py.txt",encoding="utf8")
contenu=file.read()
file.close()
 
 
def reglesjeu():
    window2=Tk()
    window2.title("Règles du jeu")
    window2.geometry("600x600")
    window2.minsize(150,150)
    window2.maxsize(800,800)
    window2.config(background='white')
    label_title2=Label(window2,text="Voici le concept et les règles du jeu de la vie:")
    label_title2.pack(side=TOP)
    labelregles=Label(window2,text=contenu,wraplength=500,justify=LEFT)
    labelregles.pack(pady=10)
 
 
def quadrillage():
  window1= Tk()
  window1.title("Jeux de la vie")
  window1.geometry("600x600")
  window1.minsize(150,150)
  window1.maxsize(800,800)
  window1.config(background='white')
 
 
 
 
  frame1=Frame(window1,bg="white")
  label_title1=Label(frame1, text="choisissez les dimensions du jeu",font=("Ariel",10),bg='white',fg='blue' )
  label_title1.pack(expand=YES)
  frame1.pack(side=TOP)
 
 
  def boutoncellule(event,i,j):
    global table
    global tablevie
    table[i][j].config(background="yellow")
    tablevie[i][j]=1
 
  def clickdroit(event,i,j):
    global table
    global tablevie
    table[i][j].config(background="white")
    tablevie[i][j]=0
 
  framjeu=Frame(window1,bg='white')
  for i in range(15):
    for j in range(15):
      d= carré_button=Button(framjeu,bg='white',width=2,height=1)
      table[i][j]=d
      d.grid(row=i, column=j)
      def gest(evt,i=i,j=j):
          return boutoncellule(evt,i,j)
      def mort(evt, i=i, j=j):
        return clickdroit(evt,i,j)
      d.bind("<Button-1>",gest)
      d.bind("<Button-3>",mort)
  framjeu.pack(expand=YES)
 
 
 
  def jeu():
     global table1
     global tablevie
     for i in range(15):
       for j in range(15):
        if 0<i<14 and 0<j<14 and tablevie[i][j]==0 and tablevie[i+1][j]+tablevie[i-1][j]+tablevie[i+1][j+1]+tablevie[i+1][j-1]+tablevie[i][j+1]+tablevie[i-1][j-1]+tablevie[i-1][j+1]+tablevie[i][j-1]==3:
            tablevie[i][j]=1
        elif  0<i<14 and 0<j<14 and tablevie[i][j]==1 and tablevie[i+1][j]+tablevie[i-1][j]+tablevie[i+1][j+1]+tablevie[i+1][j-1]+tablevie[i][j+1]+tablevie[i-1][j-1]+tablevie[i-1][j+1]+tablevie[i][j-1]==2:
            tablevie[i][j]=1
        elif  0<i<14 and 0<j<14 and tablevie[i][j]==1 and tablevie[i+1][j]+tablevie[i-1][j]+tablevie[i+1][j+1]+tablevie[i+1][j-1]+tablevie[i][j+1]+tablevie[i-1][j-1]+tablevie[i-1][j+1]+tablevie[i][j-1]==3:
            tablevie[i][j]=1
        elif  0<i<14 and 0<j<14 and tablevie[i][j]==1 and tablevie[i+1][j]+tablevie[i-1][j]+tablevie[i+1][j+1]+tablevie[i+1][j-1]+tablevie[i][j+1]+tablevie[i-1][j-1]+tablevie[i-1][j+1]+tablevie[i][j-1]==1:
            tablevie[i][j]=0
        elif  0<i<14 and 0<j<14 and tablevie[i][j]==1 and tablevie[i+1][j]+tablevie[i-1][j]+tablevie[i+1][j+1]+tablevie[i+1][j-1]+tablevie[i][j+1]+tablevie[i-1][j-1]+tablevie[i-1][j+1]+tablevie[i][j-1]>3:
            tablevie[i][j]=0
 
 
 
        if 0<j<14 and tablevie[0][j]==0 and tablevie[1][j]+tablevie[1][j+1]+tablevie[1][j-1]+tablevie[0][j+1]+tablevie[0][j-1]==3:
            tablevie[0][j]=1
        elif  0<j<14 and tablevie[0][j]==1 and tablevie[1][j]+tablevie[1][j+1]+tablevie[1][j-1]+tablevie[0][j+1]+tablevie[0][j-1]==2:
            tablevie[0][j]=1
        elif 0<j<14 and tablevie[0][j]==1 and tablevie[1][j]+tablevie[1][j+1]+tablevie[1][j-1]+tablevie[0][j+1]+tablevie[0][j-1]==3:
           tablevie[0][j]=1
        elif 0<j<14 and tablevie[0][j]==1 and tablevie[1][j]+tablevie[1][j+1]+tablevie[1][j-1]+tablevie[0][j+1]+tablevie[0][j-1]==1:
            tablevie[0][j]=0
        elif 0<j<14 and tablevie[0][j]==1 and tablevie[1][j]+tablevie[1][j+1]+tablevie[1][j-1]+tablevie[0][j+1]+tablevie[0][j-1]>3:
            tablevie[0][j]=0
 
        if 0<i<14 and tablevie[i][0]==0 and tablevie[i+1][0]+tablevie[i-1][0]+tablevie[i+1][1]+tablevie[i][1]+tablevie[i-1][1]==3:
            tablevie[i][0]=1
        elif 0<i<14 and tablevie[i][0]==1 and tablevie[i+1][0]+tablevie[i-1][0]+tablevie[i+1][1]+tablevie[i][1]+tablevie[i-1][1]==2:
            tablevie[i][0]=1
        elif 0<i<14 and tablevie[i][0]==1 and tablevie[i+1][0]+tablevie[i-1][0]+tablevie[i+1][1]+tablevie[i][1]+tablevie[i-1][1]==3:
            tablevie[i][0]=1
        elif 0<i<14 and tablevie[i][0]==1 and tablevie[i+1][0]+tablevie[i-1][0]+tablevie[i+1][1]+tablevie[i][1]+tablevie[i-1][1]==1:
           tablevie[i][0]=0
        elif 0<i<14 and  tablevie[i][0]==1 and tablevie[i+1][0]+tablevie[i-1][0]+tablevie[i+1][1]+tablevie[i][1]+tablevie[i-1][1]>3:
            tablevie[i][0]=0
 
 
 
        if 0<j<14 and tablevie[14][j]==0 and tablevie[13][j]+tablevie[14][j+1]+tablevie[14][j-1]+tablevie[13][j+1]+tablevie[13][j-1]==3:
            tablevie[14][j]=1
        elif 0<j<14 and tablevie[14][j]==1 and tablevie[13][j]+tablevie[14][j+1]+tablevie[14][j-1]+tablevie[13][j+1]+tablevie[13][j-1]==2:
            tablevie[14][j]=1
        elif 0<j<14 and tablevie[14][j]==1 and tablevie[13][j]+tablevie[14][j+1]+tablevie[14][j-1]+tablevie[13][j+1]+tablevie[13][j-1]==3:
             tablevie[14][j]=1
        elif 0<j<14 and tablevie[14][j]==1 and tablevie[13][j]+tablevie[14][j+1]+tablevie[14][j-1]+tablevie[13][j+1]+tablevie[13][j-1]==1:
            tablevie[14][j]=0
        elif 0<j<14 and tablevie[14][j]==1 and tablevie[13][j]+tablevie[14][j+1]+tablevie[14][j-1]+tablevie[13][j+1]+tablevie[13][j-1]>3:
            tablevie[14][j]=0
 
 
        if 0<i<14 and tablevie[i][14]==0 and tablevie[i+1][13]+tablevie[i-1][13]+tablevie[i+1][14]+tablevie[i][13]+tablevie[i-1][14]==3:
            tablevie[i][14]=1
        elif 0<i<14 and tablevie[i][14]==1 and tablevie[i+1][13]+tablevie[i-1][13]+tablevie[i+1][14]+tablevie[i][13]+tablevie[i-1][14]==2:
            tablevie[i][14]=1
        elif 0<i<14 and tablevie[i][14]==1 and tablevie[i+1][13]+tablevie[i-1][13]+tablevie[i+1][14]+tablevie[i][13]+tablevie[i-1][14]==3:
            tablevie[i][14]=1
        elif 0<i<14 and tablevie[i][14]==1 and tablevie[i+1][13]+tablevie[i-1][13]+tablevie[i+1][14]+tablevie[i][13]+tablevie[i-1][14]==1:
            tablevie[i][14]=0
        elif 0<i<14 and tablevie[i][14]==1 and tablevie[i+1][13]+tablevie[i-1][13]+tablevie[i+1][14]+tablevie[i][13]+tablevie[i-1][14]>3:
            tablevie[i][14]=0
 
 
 
        if tablevie[0][0]==0 and tablevie[1][0]+tablevie[0][1]+tablevie[1][1]==3:
            tablevie[0][0]=1
        elif tablevie[0][0]==1 and tablevie[1][0]+tablevie[0][1]+tablevie[1][1]==2:
            tablevie[0][0]=1
        elif tablevie[0][0]==1 and tablevie[1][0]+tablevie[0][1]+tablevie[1][1]==3:
            tablevie[0][0]=1
        elif tablevie[0][0]==1 and tablevie[1][0]+tablevie[0][1]+tablevie[1][1]==1:
            tablevie[0][0]=0
        elif tablevie[0][0]==1 and tablevie[1][0]+tablevie[0][1]+tablevie[1][1]>3:
            tablevie[0][0]=0
 
 
        if tablevie[14][0]==0 and tablevie[14][1]+tablevie[13][0]+tablevie[13][1]==3:
            tablevie[14][0]=1
        elif tablevie[14][0]==1 and tablevie[14][1]+tablevie[13][0]+tablevie[13][1]==2:
            tablevie[14][0]=1
        elif tablevie[14][0]==1 and tablevie[14][1]+tablevie[13][0]+tablevie[13][1]==3:
            tablevie[14][0]=1
        elif tablevie[14][0]==1 and tablevie[14][1]+tablevie[13][0]+tablevie[13][1]==1:
            tablevie[14][0]=0
        elif tablevie[14][0]==1 and tablevie[14][1]+tablevie[13][0]+tablevie[13][1]>3:
            tablevie[14][0]=0
 
 
        if tablevie[0][14]==0 and tablevie[1][14]+tablevie[0][13]+tablevie[1][13]==3:
            tablevie[0][14]=1
        elif tablevie[0][14]==1 and tablevie[1][14]+tablevie[0][13]+tablevie[1][13]==2:
            tablevie[0][14]=1
        elif tablevie[0][14]==1 and tablevie[1][14]+tablevie[0][13]+tablevie[1][13]==3:
            tablevie[0][14]=1
        elif tablevie[0][14]==1 and tablevie[1][14]+tablevie[0][13]+tablevie[1][13]==1:
            tablevie[0][14]=0
        elif tablevie[0][14]==1 and tablevie[1][14]+tablevie[0][13]+tablevie[1][13]>3:
            tablevie[0][14]=0
 
 
        if tablevie[14][14]==0 and tablevie[14][13]+tablevie[13][14]+tablevie[13][13]==3:
            tablevie[14][14]=1
        elif tablevie[14][14]==1 and tablevie[14][13]+tablevie[13][14]+tablevie[13][13]==2:
            tablevie[14][14]=1
        elif tablevie[14][14]==1 and tablevie[14][13]+tablevie[13][14]+tablevie[13][13]==3:
            tablevie[14][14]=1
        elif tablevie[14][14]==1 and tablevie[14][13]+tablevie[13][14]+tablevie[13][13]==1:
            tablevie[14][14]=0
        elif tablevie[14][14]==1 and tablevie[14][13]+tablevie[13][14]+tablevie[13][13]>3:
            tablevie[14][14]=0
 
 
     for i in range(15):
       for j in range(15):
           if tablevie[i][j]==1:
            d=table[i][j]
            d.config(bg="yellow")
           else:
            d=table[i][j]
            d.config(bg="white")
       #while (d).cget('white')  and (tamble[i+1][j])['yellow'] and (table[i-1][j])['yellow'] and (table[i+1][j+1])['yellow'] and (table[i+1][j-1])['yellow']:
       # d.config(bg="yellow")
 
  def jeuauto():
    while 1:
        jeu()
 
 
 
 
 
 
 
 
  def arret():
    jouer_button4.config(state=DISABLED)
  def reset():
    window1.destroy()
    quadrillage()
 
 
 
  jouer_button4=Button(window1,text='Jouer',font=("Ariel",10),bg='white',fg='blue',command=jeuauto)
  jouer_button4.pack(side=BOTTOM,pady=10)
  jouer_button5=Button(window1,text='Stop',font=("Ariel",10),bg='white',fg='blue',command=arret)
  jouer_button5.pack(side=BOTTOM)
  jouer_button6=Button(window1,text='Recommencer',font=("Ariel",10),bg='white',fg='blue',command=reset)
  jouer_button6.pack(side=BOTTOM,pady=10)
 
 
 
 
 
 
 
 
label_title=Label(frame, text="Bienvenu sur le jeu de la vie",font=("Ariel",16),bg='white',fg='blue')
label_title.pack()
 
 
 
jouer_button=Button(frame,text='Jouer',font=("Ariel",10),bg='white',fg='blue',command=quadrillage)
jouer_button.pack(pady=10)
 
jouer_button1=Button(frame,text='Règles du jeu',font=("Ariel",10),bg='white',fg='blue',command=reglesjeu)
jouer_button1.pack(pady=10)
 
 
 
 
 
 
frame.pack(expand=YES)
 
window.mainloop()