bonjour, dans 2 jours j'ai un oral de bac en isn. Je suis dans un groupe de 3 personnes et nous devons créer un morpion avec une interface tkinter. Nous avons donc repartit les taches et nous avons toutes fini notre script, cependant cela va des semaines que nous n'arrivons pas à relier les reliés ensemble alors c'est pour cela que je me dirige vers vous. Il faut donc que dans les menus de l'interface la partie de "kader" se lance quand on appuis sur le bouton "1 joueur" et que la partie "maelys" se lance quand on appuis sur le bouton "2 joueurs".

pouvez vous m'aidez?

voici les script :






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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
from tkinter import *
 
from tkinter.messagebox import *
 
import tkinter as tk
 
################################ maelys #############################    
 
def Clic(event):
 
    global a,C1,C2,C3,C1RC,C1R,C2RC,C2R,C3RC,C3R,L1RC,L1R,L2RC,L2R,L3RC,L3R,L1,L2,L3
 
    # position du pointeur de la souris
 
    X = event.x
 
    Y = event.y
 
    #Si a=1 on met une croix
 
    if a==1:
 
        if X < 100:
 
            if Y < 100:
 
                if C1[0]==2:
 
                    a=0
 
                    C1[0]=1
 
                    L1[0]=1
 
                    Croix(50,50)
 
                else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
            else :
 
                if Y < 200:
 
                    if C1[1]==2:
 
                        a=0
 
                        C1[1]=1
 
                        L2[0]=1
 
                        Croix(50,150)
 
                    else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
                else :
 
                    if C1[2]==2:
 
                        a=0
 
                        C1[2]=1
 
                        L3[0]=1
 
                        Croix(50,250)
 
                    else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
        if X < 200 and X > 100:
 
            if Y < 100:
 
                if C2[0]==3:
 
                    a=0
 
                    C2[0]=1
 
                    L1[1]=1
 
                    Croix(150,50)
 
                else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
            else :
 
                if Y < 200:
 
                    if C2[1]==3:
 
                        a=0
 
                        C2[1]=1
 
                        L2[1]=1
 
                        Croix(150,150)
 
                    else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
                else :
 
                    if C2[2]==3:
 
                        a=0
 
                        C2[2]=1
 
                        L3[1]=1
 
                        Croix(150,250)
 
                    else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
        if X < 300 and X > 200:
 
            if Y < 100:
 
                if C3[0]==4:
 
                    a=0
 
                    C3[0]=1
 
                    L1[2]=1
 
                    Croix(250,50)
 
                else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
            else :
 
                if Y < 200:
 
                    if C3[1]==4:
 
                        a=0
 
                        C3[1]=1
 
                        L2[2]=1
 
                        Croix(250,150)
 
                    else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
                else :
 
                    if C3[2]==4:
 
                        a=0
 
                        C3[2]=1
 
                        L3[2]=1
 
                        Croix(250,250)
 
                    else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
    #Ici a=0 et on met un rond
 
    else:
 
        if X < 100:
 
            if Y < 100:
 
                if C1[0]==2:
 
                    a=1
 
                    C1[0]=0
 
                    L1[0]=0
 
                    Rond(50,50)
 
                else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
            else :
 
                if Y < 200:
 
                    if C1[1]==2:
 
                        a=1
 
                        C1[1]=0
 
                        L2[0]=0
 
                        Rond(50,150)
 
                    else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
                else :
 
                    if C1[2]==2:
 
                        a=1
 
                        C1[2]=0
 
                        L3[0]=0
 
                        Rond(50,250)
 
                    else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
        if X < 200 and X > 100:
 
            if Y < 100:
 
                if C2[0]==3:
 
                    a=1
 
                    C2[0]=0
 
                    L1[1]=0
 
                    Rond(150,50)
 
                else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
            else :
 
                if Y < 200:
 
                    if C2[1]==3:
 
                        a=1
 
                        C2[1]=0
 
                        L2[1]=0
 
                        Rond(150,150)
 
                    else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
                else :
 
                    if C2[2]==3:
 
                        a=1
 
                        C2[2]=0
 
                        L3[1]=0
 
                        Rond(150,250)
 
                    else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
        if X < 300 and X > 200:
 
            if Y < 100:
 
                if C3[0]==4:
 
                    a=1
 
                    C3[0]=0
 
                    L1[2]=0
 
                    Rond(250,50)
 
                else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
            else :
 
                if Y < 200:
 
                    if C3[1]==4:
 
                        a=1
 
                        C3[1]=0
 
                        L2[2]=0
 
                        Rond(250,150)
 
                    else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
                else :
 
                    if C3[2]==4:
 
                        a=1
 
                        C3[2]=0
 
                        L3[2]=0
 
                        Rond(250,250)
 
                    else :
 
                        showinfo(title='Non',message='Tu ne peux pas !')
 
#ici on créer la fonction pour afficher les ronds
 
def Rond(x1,y1):
 
    global C1,C2,C3
 
    Canevas.create_oval (x1 - 35, y1 - 35, x1 + 35, y1 + 35, fill = 'red')
 
    Canevas.create_oval(x1 - 30, y1 - 30, x1+20, y1+20, fill = 'white')
 
    Verif()
 
#ici on créer la fonction pour afficher les croix
 
def Croix(x1,y1):
 
    global C1,C2,C3
 
    Canevas.create_line(x1-35, y1+35, x1+35, y1-35, width = 5, fill = 'blue')
 
    Canevas.create_line(x1-35, y1-35, x1+35, y1+35, width = 5, fill = 'blue')
 
    Verif()
 
#ici on créer la fonction qui compte les points
 
def Verif():
 
    global C1, C2,C3,C1RC,C1R,C2RC,C2R,C3RC,C3R,L1RC,L1R,L2RC,L2R,L3RC,L3R,L1,L2,L3
 
    C1RC = C1.count(1)
 
    C1R = C1.count(0)
 
    C2RC = C2.count(1)
 
    C2R = C2.count(0)
 
    C3RC = C3.count(1)
 
    C3R = C3.count(0)
 
    L1RC = L1.count(1)
 
    L1R = L1.count(0)
 
    L2RC = L2.count(1)
 
    L2R = L2.count(0)
 
    L3RC = L3.count(1)
 
    L3R = L3.count(0)
 
    #ici on affiche le joueur qui a gagner 
 
    if C1RC == 3:
 
        showinfo(title='Gagne',message='Joueur 1 a Gagner !')
 
    if C1R == 3:
 
        showinfo(title='Gagne',message='Joueur 2 a Gagner !')
 
    if C2RC == 3:
 
        showinfo(title='Gagne',message='Joueur 1 a Gagner !')
 
    if C2R == 3:
 
        showinfo(title='Gagne',message='Joueur 2 a Gagner !')
 
    if C3RC == 3:
 
        showinfo(title='Gagne',message='Joueur 1 a Gagner !')
 
    if C3R == 3:
 
        showinfo(title='Gagne',message='Joueur 2 a Gagner !')
 
    if C1[0]==1 and C2[1]==1 and C3[2]==1: 
 
        showinfo(title='Gagne',message='Joueur 1 a Gagner !')
 
    if C1[2]==1 and C2[1]==1 and C3[0]==1: 
 
        showinfo(title='Gagne',message='Joueur 1 a Gagner !')    
 
    if C1[0]==0 and C2[1]==0 and C3[2]==0: 
 
        showinfo(title='Gagne',message='Joueur 2 a Gagner !')
 
    if C1[2]==0 and C2[1]==0 and C3[0]==0: 
 
        showinfo(title='Gagne',message='Joueur 2 a Gagner !')  
 
    if L1RC == 3:
 
        showinfo(title='Gagne',message='Joueur 1 a Gagner !')
 
    if L1R == 3:
 
        showinfo(title='Gagne',message='Joueur 2 a Gagner !')
 
    if L2RC == 3:
 
        showinfo(title='Gagne',message='Joueur 1 a Gagner !')
 
    if L2R == 3:
 
        showinfo(title='Gagne',message='Joueur 2 a Gagner !')
 
    if L3RC == 3:
 
        showinfo(title='Gagne',message='Joueur 1 a Gagner !')
 
    if L3R == 3:
 
        showinfo(title='Gagne',message='Joueur 2 a Gagner !')
 
#ici on initialise les colones et les lignes
 
C1RC,C1R,C2RC,C2R,C3RC,C3R,L1RC,L1R,L2RC,L2R,L3RC,L3R = 0,0,0,0,0,0,0,0,0,0,0,0
 
a=1
 
C1=[2,2,2]
 
L1=[2,2,2]
 
C2=[3,3,3]
 
L2=[3,3,3]
 
C3=[4,4,4]
 
L3=[4,4,4]
 
print(C1)
 
############################amel######################"
 
# Création de la fenêtre principale
 
Mafenetre = Tk()
 
Mafenetre.title("Morpion par MKA")
 
# Création d'un widget Canvas
 
Largeur = 300
 
Hauteur = 300
 
Canevas = Canvas(Mafenetre, width = Largeur, height =Hauteur, bg ="white")
 
# La méthode bind() permet de lier un événement avec une fonction :
 
# un clic gauche sur la zone graphique provoquera l'appel de la fonction utilisateur Clic()
 
Canevas.bind("<Button-1>", Clic)
 
Canevas.pack(padx =5, pady =5)
 
#ici on créer les lignes qui délimite les colones et les cases
 
Canevas.create_line(105, 10, 105, 290, width = 5)
 
Canevas.create_line(205, 10, 205, 290, width = 5)
 
Canevas.create_line(10, 105, 290, 105, width = 5)
 
Canevas.create_line(10, 205, 290, 205, width = 5)
 
mainmenu = tk.Menu(Mafenetre)
 
menuOptions = tk.Menu(mainmenu)  ## Menu Fils
 
menuOptions.add_command(label = "Recommencer" , command = Mafenetre.quit)
 
menuOptions.add_command(label = "Quitter" , command = Mafenetre.destroy)
 
menuModes = tk.Menu(mainmenu) ## Menu Fils
 
menuModes.add_command(label = "1 joueurs", command =Clic)
 
menuModes.add_command(label = "2 joueurs", command =Clic) 
 
mainmenu.add_cascade(label = "Options", menu = menuOptions)
 
mainmenu.add_cascade(label = "Modes", menu = menuModes)
 
Mafenetre.config(menu=mainmenu)
 
Mafenetre.mainloop()
Et l'autre

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
########## kader ########
 
def ModeOrdi(self, mode): #passage ou non en mode ordi
        global modeordi, tour
        modeordi = mode
        if mode == True :
            tour = "j1"
        self.Reinit()
 
def CoupOrdi(self): #cree un coup aleatoire
        global grille, carre, tour, nb_coup
        coupX, coupY= randrange(0,3), randrange(0,3)
        if fini == False :
            while 1 : # en gros, tant que le coup sera sur une case occupee, il relancera l'aleatoire
                coupX = randrange(0,3)
                coupY = randrange(0,3)
                if grille[coupY][coupX] == "":
                    grille[coupY][coupX] = "O"
                    break
        nb_coup += 1 #augmenter le nombre de coups joues
        tour ="j1" # c'est e j1 de jouer
        self.carre[coupX][coupY].Raffraichir()
 
 
def Reinit(self): #remise e 0
        if self.Du_Son :
            jeu.bell()
        global grille, nb_coup, fini, tour
        grille=[["","",""],\
         ["","",""],\
         ["","",""]]
        nb_coup=0
        fini=False
        matchnul = False
        self.carre=[[[],[],[]],\
               [[],[],[]],\
               [[],[],[]]]
        for a in range(3):
            for i in range(3):
                self.carre[a][i]=Carre(a,i)
        if modeordi == True :
            tour = "j1"
 
 
def Verifier(self): #verification des positions des X et des O
        self.j.config(text="Joueur "+tour[1]+", c'est ton tour")
        global fini, nb_coup, son, matchnul
        if nb_coup == 9 : #quand toutes les cases sont occupees, match nul
            self.j.config(text="Match Nul !")
            matchnul = True
 
        if grille[0][0]==grille[0][1] and grille[0][0]==grille[0][2] and grille[0][0] != "" :
            if grille[0][0]=="X":
                self.j.config(text="Joueur 1 a Gagne !")
            elif grille[0][0]=="O":
                self.j.config(text="Joueur 2 a Gagne !")
            if son :
                Bip(2)
            fini =True
 
        elif grille[1][0]==grille[1][1] and grille[1][0]==grille[1][2] and grille[1][0] != "" :
            if grille[1][0]=="X":
                self.j.config(text="Joueur 1 a Gagne !")
            elif grille[1][0]=="O":
                self.j.config(text="Joueur 2 a Gagne !")
            if son :
                Bip(2)
            fini =True
 
        elif grille[2][0]==grille[2][1] and grille[2][0]==grille[2][2] and grille[2][0] != "" :
            if grille[2][0]=="X":
                self.j.config(text="Joueur 1 a Gagne !")
            elif grille[2][0]=="O":
                self.j.config(text="Joueur 2 a Gagne !")
            fini =True
 
 
        elif grille[0][0]==grille[1][0] and grille[0][0]==grille[2][0] and grille[0][0] != "" :
            if grille[0][0]=="X":
                self.j.config(text="Joueur 1 a Gagne !")
            elif grille[0][0]=="O":
                self.j.config(text="Joueur 2 a Gagne !")
            if son :
                Bip(2)
            fini =True
 
        elif grille[0][1]==grille[1][1] and grille[0][1]==grille[2][1] and grille[0][1] != "" :
            if grille[0][1]=="X":
                self.j.config(text="Joueur 1 a Gagne !")
            elif grille[0][1]=="O":
                self.j.config(text="Joueur 2 a Gagne !")
            if son :
                Bip(2)
            fini =True
 
        elif grille[0][2]==grille[1][2] and grille[0][2]==grille[2][2] and grille[0][2] != "" :
            if grille[0][2]=="X":
                self.j.config(text="Joueur 1 a Gagne !")
            elif grille[0][2]=="O":
                self.j.config(text="Joueur 2 a Gagne !")
            if son :
                Bip(2)
            fini =True
 
        elif grille[0][0]==grille[1][1] and grille[0][0]==grille[2][2] and grille[0][0] != "" :
            if grille[0][0]=="X":
                self.j.config(text="Joueur 1 a Gagne !")
            elif grille[0][0]=="O":
                self.j.config(text="Joueur 2 a Gagne !")
            fini =True
 
        elif grille[0][2]==grille[1][1] and grille[0][2]==grille[2][0] and grille[0][2] != "" :
            if grille[0][2]=="X":
                self.j.config(text="Joueur 1 a Gagne !")
            elif grille[0][2]=="O":
                self.j.config(text="Joueur 2 a Gagne !")
            if son :
                Bip(2)
            fini =True
 
        if matchnul :
            Bip(3)
            fini= True
 
        if fini == True :
            matchnul=False
            nb_coup=0