IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

Passer d'une fenêtre à une autre et inversement


Sujet :

Tkinter Python

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2019
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2019
    Messages : 2
    Points : 3
    Points
    3
    Par défaut Passer d'une fenêtre à une autre et inversement
    Bonjour, je suis actuellement en term S et je fait ISN, avec mon groupe on a programmé une bataille navale avec tkinter : le menu et le jeu. Le problème c'est qu'ils appartiennent à 2 programmes différents et que je n'arrive pas à les réunifier pour n'en former qu'un seul. Il faudrait que je puisse passé du menu au jeu (facile) mais ensuite que je puisse réinitialiser le jeu et/ou repasser sur le menu (là je bloque), je souhaiterai donc de l'aide pour ce bloquage pour clôturer le jeu (c'est notre dernière étape)

    Programme du menu :

    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
    from tkinter import *
    from PIL import ImageTk, Image
     
    def tuto():
        bouton.destroy()
        bouton2.destroy()
        bouton3.destroy()             #NOTE : j'ai pas supprimé les labels, et pas besoin de supprimer le bouton4, il suffit juste de poser par dessus.
        niveau.destroy()              #NOTE2 : par contre, il faudra les supprimer à la fin en masse
        niveau2.destroy()
        boutoncredits.destroy()
     
        etape1 = Label(Menufenetre, text="Etape 1 :")
        imageniveau = canvas.create_window(250,175, window=etape1)
     
        etape2 = Label(Menufenetre, text="Etape 2 :")
        imageniveau = canvas.create_window(250,375, window=etape2)
     
        bouton4 = Button(Menufenetre, text="=>", command=tutosuite) #START
        boutonfenetre = canvas.create_window(440, 560, window=bouton4)
     
    def tutosuite():
        global tuto
        global bouton4
     
        etape3 = Label(Menufenetre, text="Etape 3 :")
        imageniveau = canvas.create_window(250,175, window=etape3)
     
        etape4 = Label(Menufenetre, text="Etape 4 :")
        imageniveau = canvas.create_window(250,375, window=etape4)
     
        bouton5 = Button(Menufenetre, text="<╝", command=retour) #START
        boutonfenetre = canvas.create_window(440, 560, window=bouton5)   #NOTE3 : ICI
     
    def retour():
        global niveau
        global bouton
        global bouton2
        global bouton3
        global boutoncredits
        global niveau2
     
        bouton = Button(Menufenetre, text="START", command=jouer, foreground='blue' ) #START
        boutonfenetre = canvas.create_window(250, 175, window=bouton)
     
        niveau = Label(Menufenetre, text='Choix du niveau de difficulté :') #choix
        imageniveau = canvas.create_window(250, 250, window=niveau)
     
        bouton2 = Button(Menufenetre, text=" DEBUTANT ") #DEBUTANT
        boutonfenetre = canvas.create_window(250, 300, window=bouton2)
     
        niveau2 = Label(Menufenetre, text='niveau sélectionné') #choix
        imageniveau = canvas.create_window(350, 300, window=niveau2)
     
        bouton3 = Button(Menufenetre, text="    TUTORIEL    ", command=tuto) #TUTORIEL
        boutonfenetre = canvas.create_window(250, 350, window=bouton3)
     
        boutoncredits = Button(Menufenetre, text="Credits", command=credits) #credits
        boutonfenetre = canvas.create_window(435, 560, window=boutoncredits)
     
    def credits():   #affichage des credits
        global gens1
        global gens2
        global gens3
        global retour2
        bouton.destroy()
        bouton2.destroy()
        bouton3.destroy()
        niveau.destroy()
        niveau2.destroy()
        boutoncredits.destroy()
        gens1 = Label(Menufenetre, text='Samuel MABIT') #choix
        gens1bis = canvas.create_window(250, 220, window=gens1)
        gens2 = Label(Menufenetre, text='Ange DUVAL') #choix
        gens2bis = canvas.create_window(250, 260, window=gens2)
        gens3 = Label(Menufenetre, text='Justin GLEMAREC') #choix
        gens3bis = canvas.create_window(250, 300, window=gens3)
        bouton4 = Button(Menufenetre, text="<╝", command=retour2) #START
        boutonfenetre = canvas.create_window(440, 560, window=bouton4)
     
    def retour2():     # flèche retour
        global niveau
        global bouton
        global bouton2
        global bouton3
        global boutoncredits
        global niveau2
        gens1.destroy()
        gens2.destroy()
        gens3.destroy()
     
        bouton = Button(Menufenetre, text="START", command=jouer, foreground='blue' ) #START
        boutonfenetre = canvas.create_window(250, 175, window=bouton)
     
        niveau = Label(Menufenetre, text='Choix du niveau de difficulté :') #choix
        imageniveau = canvas.create_window(250, 250, window=niveau)
     
        bouton2 = Button(Menufenetre, text=" DEBUTANT ") #DEBUTANT
        boutonfenetre = canvas.create_window(250, 300, window=bouton2)
     
        niveau2 = Label(Menufenetre, text='niveau sélectionné') #choix
        imageniveau = canvas.create_window(350, 300, window=niveau2)
     
        bouton3 = Button(Menufenetre, text="    TUTORIEL    ", command=tuto) #TUTORIEL
        boutonfenetre = canvas.create_window(250, 350, window=bouton3)
     
        boutoncredits = Button(Menufenetre, text="Credits", command=credits) #credits
        boutonfenetre = canvas.create_window(435, 560, window=boutoncredits)
     
    # PROGRAMME DE BASE
     
    Menufenetre = Tk()
    Menufenetre.title('Bataille Navale One Piece') #titre de la fenetre
     
    canvas = Canvas(Menufenetre, bg = "blue", height = 600, width =500) #dimensions
    canvas.pack()
     
    canvas.pack(expand = YES, fill = BOTH) #placement du fond de la fenetre
    img = PhotoImage(file='fond.PNG')
    canvas.create_image(252,305, image=img)
     
    canvas.pack(expand = YES, fill = BOTH) #placement du bateau
    img2 = PhotoImage(file='sunny.png')
    canvas.create_image(250,475, image=img2)
     
    canvas.pack(expand = YES, fill = BOTH) #placement du ONE PIECE
    img3 = PhotoImage(file='titre.png')
    canvas.create_image(250,50, image=img3)
     
    Menufenetre.config(cursor='pirate')
    bouton = Button(Menufenetre, text="START", command=jouer, foreground='blue' ) #START
    boutonfenetre = canvas.create_window(250, 175, window=bouton)
     
    niveau = Label(Menufenetre, text='Choix du niveau de difficulté :') #choix
    imageniveau = canvas.create_window(250, 250, window=niveau)
     
    bouton2 = Button(Menufenetre, text=" DEBUTANT ") #DEBUTANT
    boutonfenetre = canvas.create_window(250, 300, window=bouton2)
     
    niveau2 = Label(Menufenetre, text='niveau sélectionné') #niveau selctionné
    imageniveau = canvas.create_window(350, 300, window=niveau2)
     
    bouton3 = Button(Menufenetre, text="    TUTORIEL    ", command=tuto) #TUTORIEL
    boutonfenetre = canvas.create_window(250, 350, window=bouton3)
     
    boutoncredits = Button(Menufenetre, text="Credits", command=credits) #credits
    boutonfenetre = canvas.create_window(435, 560, window=boutoncredits)
     
    canvas.pack()
    Menufenetre.mainloop()
     
    #Menufenetre                1
    #canvas                     2
    #img                        3
    #img2                       4
    #img3                       5
    #bouton1                    6
    #bouton2                    7
    #bouton3                    8
    #bouton4                    9
    #boutonfenetre              10
    #boutoncredits              11
    #niveau                     12
    #niveau2                    13
    #imageniveau                14
    #jouer                      15
    #tuto                       16
    #etape1                     17
    #etape2                     18
    #tutosuite                  19
    #etape3                     20
    #etape4                     21
    #bouton5                    22
    Programme du jeu :

    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
    from tkinter import *
    from random import randint
    from tkinter import font
     
    fenetre = Tk()
     
    fenetre.title('Bataille Navale')
     
    bateau=[]
    case_ordi=[]
    case_joueur=[]
    bateau_j=[]
    case_touché=[]
    case_touché_j=[]
     
    police=font.Font(size=30)
    police_b=font.Font(size=10)
     
    c = Canvas(fenetre, width = 740, height = 480, bg='white')
    r=c.create_rectangle(30, 30, 350, 350, fill="blue")
    line1 = c.create_line(30,0,30,350, width=2) #Grille 1, barres verticales
    line2 = c.create_line(62,0,62,350, width=2)
    line3 = c.create_line(94,0,94,350, width=2)
    line4 = c.create_line(126,0,126,350, width=2)
    line5 = c.create_line(158,0,158,350, width=2)
    line6 = c.create_line(190,0,190,350, width=2)
    line7 = c.create_line(222,0,222,350, width=2)
    line8 = c.create_line(254,0,254,350, width=2)
    line9 = c.create_line(286,0,286,350, width=2)
    line10 = c.create_line(318,0,318,350, width=2)
    line11 = c.create_line(350,0,350,350, width=2)
    line12 = c.create_line(0,30,350,30, width=2) #Barres horyzontales
    line13 = c.create_line(0,62,350,62, width=2)
    line14 = c.create_line(0,94,350,94, width=2)
    line15 = c.create_line(0,126,350,126, width=2)
    line16 = c.create_line(0,158,350,158, width=2)
    line17 = c.create_line(0,190,350,190, width=2)
    line18 = c.create_line(0,222,350,222, width=2)
    line19 = c.create_line(0,254,350,254, width=2)
    line20 = c.create_line(0,286,350,286, width=2)
    line21 = c.create_line(0,318,350,318, width=2)
    line22 = c.create_line(0,350,350,350, width=2)
    case = c.create_rectangle(0,0,30,30, fill="black") #Case noire
    id_text = c.create_text(15,15, text='X', font="Arial 16") #Texte coordonée
    id_text = c.create_text(15,47, text='1', font="Arial 16")
    id_text = c.create_text(15,79, text='2', font="Arial 16")
    id_text = c.create_text(15,111, text='3', font="Arial 16")
    id_text = c.create_text(15,143, text='4', font="Arial 16")
    id_text = c.create_text(15,175, text='5', font="Arial 16")
    id_text = c.create_text(15,207, text='6', font="Arial 16")
    id_text = c.create_text(15,239, text='7', font="Arial 16")
    id_text = c.create_text(15,271, text='8', font="Arial 16")
    id_text = c.create_text(15,303, text='9', font="Arial 16")
    id_text = c.create_text(15,335, text='10', font="Arial 16")
    txt = c.create_text(45, 15, text="A", font="Arial 16")
    txt = c.create_text(77, 15, text="B", font="Arial 16")
    txt = c.create_text(109, 15, text="C", font="Arial 16")
    txt = c.create_text(141, 15, text="D", font="Arial 16")
    txt = c.create_text(173, 15, text="E", font="Arial 16")
    txt = c.create_text(205, 15, text="F", font="Arial 16")
    txt = c.create_text(237, 15, text="G", font="Arial 16")
    txt = c.create_text(269, 15, text="H", font="Arial 16")
    txt = c.create_text(301, 15, text="I", font="Arial 16")
    txt = c.create_text(333, 15, text="J", font="Arial 16")
    line23 = c.create_line(367,0,367,360, width=10) # ligne séparation des deux grilles
    r=c.create_rectangle(414, 30, 734, 350, fill="blue")
    line0 = c.create_line(384,0,384,350, width=2) #Grille 2, barres verticales
    line1 = c.create_line(414,0,414,350, width=2)
    line2 = c.create_line(446,0,446,350, width=2)
    line3 = c.create_line(478,0,478,350, width=2)
    line4 = c.create_line(510,0,510,350, width=2)
    line5 = c.create_line(542,0,542,350, width=2)
    line6 = c.create_line(574,0,574,350, width=2)
    line7 = c.create_line(606,0,606,350, width=2)
    line8 = c.create_line(638,0,638,350, width=2)
    line9 = c.create_line(670,0,670,350, width=2)
    line10 = c.create_line(702,0,702,350, width=2)
    line11 = c.create_line(734,0,734,350, width=2)
    line12 = c.create_line(384,30,734,30, width=2) #Barres horyzontales
    line13 = c.create_line(384,62,734,62, width=2)
    line14 = c.create_line(384,94,734,94, width=2)
    line15 = c.create_line(384,126,734,126, width=2)
    line16 = c.create_line(384,158,734,158, width=2)
    line17 = c.create_line(384,190,734,190, width=2)
    line18 = c.create_line(384,222,734,222, width=2)
    line19 = c.create_line(384,254,734,254, width=2)
    line20 = c.create_line(384,286,734,286, width=2)
    line21 = c.create_line(384,318,734,318, width=2)
    line22 = c.create_line(384,350,734,350, width=2)
    case = c.create_rectangle(384,0,414,30, fill="black") #Case noire
    id_text = c.create_text(399,15, text='X', font="Arial 16") #Texte coordonée
    id_text = c.create_text(399,47, text='1', font="Arial 16")
    id_text = c.create_text(399,79, text='2', font="Arial 16")
    id_text = c.create_text(399,111, text='3', font="Arial 16")
    id_text = c.create_text(399,143, text='4', font="Arial 16")
    id_text = c.create_text(399,175, text='5', font="Arial 16")
    id_text = c.create_text(399,207, text='6', font="Arial 16")
    id_text = c.create_text(399,239, text='7', font="Arial 16")
    id_text = c.create_text(399,271, text='8', font="Arial 16")
    id_text = c.create_text(399,303, text='9', font="Arial 16")
    id_text = c.create_text(399,335, text='10', font="Arial 16")
    txt = c.create_text(429, 15, text="A", font="Arial 16")
    txt = c.create_text(461, 15, text="B", font="Arial 16")
    txt = c.create_text(493, 15, text="C", font="Arial 16")
    txt = c.create_text(525, 15, text="D", font="Arial 16")
    txt = c.create_text(557, 15, text="E", font="Arial 16")
    txt = c.create_text(589, 15, text="F", font="Arial 16")
    txt = c.create_text(621, 15, text="G", font="Arial 16")
    txt = c.create_text(653, 15, text="H", font="Arial 16")
    txt = c.create_text(685, 15, text="I", font="Arial 16")
    txt = c.create_text(717, 15, text="J", font="Arial 16")
     
    def bateau_ordi(): #L'ordi choisit tout ses bateau
        bateau_ordi2()
        bateau_ordi3()
        bateau_ordi3_1()
        bateau_ordi4()
        bateau_ordi5()
     
    def bateau_ordi2(): #Bateau ordi à deux cases
        a=1
        b=1
        while appartient_grille(a,b,1)==0 :
            h = randint(1,10)*32+29
            m = randint(1,10)*32+29
            a=randint(1,2)
            if a==1:
                a=h
                b=m+32
            if a==2:
                a=h+32
                b=m
        bateau.append([h,m])
        bateau.append([a,b])
     
    def bateau_ordi3(): #Premier bateau ordi à trois cases
        a=1
        b=1
        c=1
        d=1
        while appartient_grille(a,b,1)==0 or appartient_grille(c,d,1)==0 or appartient_liste(a,b,2,bateau)==1 or appartient_liste(c,d,2,bateau)==1 or appartient_liste(h,m,2,bateau)==1:
            h = randint(1,10)*32+29
            m = randint(1,10)*32+29
            a=randint(1,2)
            if a==1:
                a=h
                b=m+32
                c=h
                d=m-32
            if a==2:
                a=h+32
                b=m
                c=h-32
                d=m
        bateau.append([c,d])
        bateau.append([h,m])
        bateau.append([a,b])
     
    def bateau_ordi3_1(): #Deuxieme bateau ordi à trois cases
        a=1
        b=1
        c=1
        d=1
        while appartient_grille(a,b,1)==0 or appartient_grille(c,d,1)==0 or appartient_liste(a,b,5,bateau)==1 or appartient_liste(c,d,5,bateau)==1 or appartient_liste(h,m,5,bateau)==1:
           h = randint(1,10)*32+29
           m = randint(1,10)*32+29
           a=randint(1,2)
           if a==1:
               a=h
               b=m+32
               c=h
               d=m-32
           if a==2:
               a=h+32
               b=m
               c=h-32
               d=m
        bateau.append([c,d])
        bateau.append([h,m])
        bateau.append([a,b])
     
    def bateau_ordi4(): #Bateau ordi à quatre cases
        a=1
        b=1
        c=1
        d=1
        while appartient_grille(a,b,1)==0 or appartient_grille(c,d,1)==0 or appartient_liste(a,b,8,bateau)==1 or appartient_liste(c,d,8,bateau)==1 or appartient_liste(h,m,8,bateau)==1 or appartient_liste(g,i,8,bateau)==1:
           h=randint(1,10)*32+29
           m=randint(1,10)*32+29
           a=randint(1,2)
           if a==1:
               a=h
               b=m+32
               g=h
               i=m-32
               c=h
               d=m-64
           if a==2:
               a=h+32
               b=m
               g=h-32
               i=m
               c=h-64
               d=m
        bateau.append([c,d])
        bateau.append([g,i])
        bateau.append([h,m])
        bateau.append([a,b])
     
    def bateau_ordi5(): #Bateau ordi à cinq cases
        a=1
        b=1
        c=1
        d=1
        while appartient_grille(a,b,1)==0 or appartient_grille(c,d,1)==0 or appartient_liste(a,b,12,bateau)==1 or appartient_liste(c,d,12,bateau)==1 or appartient_liste(h,m,12,bateau)==1 or appartient_liste(e,f,12,bateau)==1 or appartient_liste(g,i,12,bateau)==1:
            h=randint(1,10)*32+29
            m=randint(1,10)*32+29
            a=randint(1,2)
            if a==1:
                e=h
                f=m+32
                g=h
                i=m-32
                a=h
                b=m+64
                c=h
                d=m-64
            if a==2:
                e=h+32
                f=m
                g=h-32
                i=m
                a=h+64
                b=m
                c=h-64
                d=m
        bateau.append([c,d])
        bateau.append([g,i])
        bateau.append([h,m])
        bateau.append([e,f])
        bateau.append([a,b])
     
    def partie(x,y):
        global bateau
        global bateau_j
        global case_joueur
        global case_touché_j
        n=len(case_touché_j)
        N=len(case_joueur)
        if len(case_ordi)<17:
           if len(case_joueur)<17:
               if len(case_touché)==len(case_touché_j):
                    x=(x//32)*32+29
                    y=(y//32)*32+29
                    if appartient_grille(x,y,1)==1:
                        if appartient_liste(x,y,n,case_touché_j)==0:   #si x et y appartiennent a bareau, alors rectangle rouge (touché), sinon petit rectangle blanc (à l'eau)
                            if appartient_liste(x,y,17,bateau)==1:
                               u=c.create_rectangle(x-30, y-30, x+0, y+0, fill="red")
                               case_joueur.append([x,y])
                               if appartient_liste(bateau[0][0],bateau[0][1],N+1,case_joueur)==1 and appartient_liste(bateau[1][0],bateau[1][1],N+1,case_joueur)==1 :
                                    coulé2=Label(fenetre, text='BATEAU DE 2 COULE', bg="black",fg="white", relief=GROOVE, font=police_b)
                                    c2=c.create_window(111, 390, window=coulé2, height=18, width=150)
                               if appartient_liste(bateau[2][0],bateau[2][1],N+1,case_joueur)==1 and appartient_liste(bateau[3][0],bateau[3][1],N+1,case_joueur)==1 and appartient_liste(bateau[4][0],bateau[4][1],N+1,case_joueur)==1:
                                    coulé3=Label(fenetre, text='BATEAU DE 3 COULE', bg="black",fg="white", relief=GROOVE, font=police_b)
                                    c3=c.create_window(111, 410, window=coulé3, height=18, width=150)
                               if appartient_liste(bateau[5][0],bateau[5][1],N+1,case_joueur)==1 and appartient_liste(bateau[6][0],bateau[6][1],N+1,case_joueur)==1 and appartient_liste(bateau[7][0],bateau[7][1],N+1,case_joueur)==1:
                                    coulé3b=Label(fenetre, text='BATEAU DE 3 COULE', bg="black",fg="white", relief=GROOVE, font=police_b)
                                    c3b=c.create_window(111, 430, window=coulé3b, height=18, width=150)
                               if appartient_liste(bateau[8][0],bateau[8][1],N+1,case_joueur)==1 and appartient_liste(bateau[9][0],bateau[9][1],N+1,case_joueur)==1 and appartient_liste(bateau[10][0],bateau[10][1],N+1,case_joueur)==1 and appartient_liste(bateau[11][0],bateau[11][1],N+1,case_joueur)==1:
                                    coulé4=Label(fenetre, text='BATEAU DE 4 COULE', bg="black",fg="white", relief=GROOVE, font=police_b)
                                    c4=c.create_window(111, 450, window=coulé4, height=18, width=150)
                               if appartient_liste(bateau[12][0],bateau[12][1],N+1,case_joueur)==1 and appartient_liste(bateau[13][0],bateau[13][1],N+1,case_joueur)==1 and appartient_liste(bateau[14][0],bateau[14][1],N+1,case_joueur)==1 and appartient_liste(bateau[15][0],bateau[15][1],N+1,case_joueur)==1 and appartient_liste(bateau[16][0],bateau[16][1],N+1,case_joueur)==1:
                                    coulé5=Label(fenetre, text='BATEAU DE 5 COULE', bg="black",fg="white", relief=GROOVE, font=police_b)
                                    c5=c.create_window(111, 470, window=coulé5, height=18, width=150)
                               if len(case_joueur)==17 :
                                    gagner=Label(fenetre, text='VOUS AVEZ GAGNE !!!!', bg='white', relief=GROOVE, font=police)
                                    g=c.create_window(366, 174, window=gagner, height=45, width=490)
     
                            else:
                                v=c.create_rectangle(x-21, y-21, x-10, y-10, fill="white")
                            case_touché_j.append([x,y])
                            if len(case_joueur)<17:
                                ordi=Label(fenetre, text='L ENNEMI JOUE...', bg='white', relief=GROOVE, font=police_b)
                                o=c.create_window(368, 392, window=ordi, height=25, width=352)
                                c.after(1500,ordi_joue)
     
    def ordi_joue():
        global case_touché
        global bateau_j
        global case_ordi
        p=len(case_ordi)
        m=len(case_touché)
        x=randint(1,10)*32+29+384
        y=randint(1,10)*32+29
        if appartient_liste(x,y,m,case_touché)==0 :
            if appartient_liste(x,y,17,bateau_j)==1:
                u=c.create_line(x-32,y-32,x+1,y,fill='black', width=3)
                v=c.create_line(x-31,y,x+2,y-32,fill='black', width=3)
                case_ordi.append([x,y])
                if appartient_liste(bateau_j[0][0],bateau_j[0][1],p+1,case_ordi)==1 and appartient_liste(bateau_j[1][0],bateau_j[1][1],p+1,case_ordi)==1 :
                    coulé2o=Label(fenetre, text='BATEAU DE 2 COULE', bg="black",fg="white", relief=GROOVE, font=police_b)
                    c2o=c.create_window(626, 390, window=coulé2o, height=18, width=150)
                if appartient_liste(bateau_j[2][0],bateau_j[2][1],p+1,case_ordi)==1 and appartient_liste(bateau_j[3][0],bateau_j[3][1],p+1,case_ordi)==1 and appartient_liste(bateau_j[4][0],bateau_j[4][1],p+1,case_ordi)==1:
                    coulé3o=Label(fenetre, text='BATEAU DE 3 COULE', bg="black",fg="white", relief=GROOVE, font=police_b)
                    c3o=c.create_window(626, 410, window=coulé3o, height=18, width=150)
                if appartient_liste(bateau_j[5][0],bateau_j[5][1],p+1,case_ordi)==1 and appartient_liste(bateau_j[6][0],bateau_j[6][1],p+1,case_ordi)==1 and appartient_liste(bateau_j[7][0],bateau_j[7][1],p+1,case_ordi)==1:
                    coulé3bo=Label(fenetre, text='BATEAU DE 3 COULE', bg="black",fg="white", relief=GROOVE, font=police_b)
                    c3bo=c.create_window(626, 430, window=coulé3bo, height=18, width=150)
                if appartient_liste(bateau_j[8][0],bateau_j[8][1],p+1,case_ordi)==1 and appartient_liste(bateau_j[9][0],bateau_j[9][1],p+1,case_ordi)==1 and appartient_liste(bateau_j[10][0],bateau_j[10][1],p+1,case_ordi)==1 and appartient_liste(bateau_j[11][0],bateau_j[11][1],p+1,case_ordi)==1:
                    coulé4o=Label(fenetre, text='BATEAU DE 4 COULE', bg="black",fg="white", relief=GROOVE, font=police_b)
                    c4o=c.create_window(626, 450, window=coulé4o, height=18, width=150)
                if appartient_liste(bateau_j[12][0],bateau_j[12][1],p+1,case_ordi)==1 and appartient_liste(bateau_j[13][0],bateau_j[13][1],p+1,case_ordi)==1 and appartient_liste(bateau_j[14][0],bateau_j[14][1],p+1,case_ordi)==1 and appartient_liste(bateau_j[15][0],bateau_j[15][1],p+1,case_ordi)==1 and appartient_liste(bateau_j[16][0],bateau_j[16][1],p+1,case_ordi)==1:
                    coulé5o=Label(fenetre, text='BATEAU DE 5 COULE', bg="black",fg="white", relief=GROOVE, font=police_b)
                    c5o=c.create_window(626, 470, window=coulé5o, height=18, width=150)
                if len(case_ordi)==17:
                        perdu=Label(fenetre, text='VOUS AVEZ PERDU !!!!', bg='white', relief=GROOVE, font=police)
                        p=c.create_window(366, 174, window=perdu, height=45, width=490)
            else:
                f=c.create_rectangle(x-21, y-21, x-10, y-10, fill="white")
            case_touché.append([x,y])
            joué=Label(fenetre, text='A VOUS DE JOUER !!!', bg='white', relief=GROOVE, font=police_b)
            j=c.create_window(368, 392, window=joué, height=25, width=352)
        else : ordi_joue()
     
    def appartient_liste(x,y,q,liste): #si x et y appartient a une meme liste alors retourner 1, sinon retourner 0
        for r in range (q):
            if liste[r][0]==x:
                if liste[r][1]==y:
                    return 1
        return 0
     
    def appartient_grille(a,b,c): #si la case (a;b) appartient à la grille c, alors retourner 1, sionon retourner 0
        if c==1:
            if 32<a<350 and 32<b<350:
                return 1
            else: return 0
        if c==2:
            if 413<a<735 and 32<b<350:
                return 1
            else : return 0
     
    def àcoté(x,y,a,b,liste):
        if a==1:
            if [x,y+32]==liste[b] or [x,y-32]==liste[b] or [x+32,y]==liste[b] or [x-32,y]==liste[b]:
                return True
        if a==2:
            if liste[b][0]==liste[b-1][0]==x :
                f=y+32
                g=y-32
                if liste[b][1]==f or liste[b][1]==g or liste[b-1][1]==g or liste[b-1][1]==f:
                    return True
            if liste[b][1]==liste[b-1][1]==y :
                f=x+32
                g=x-32
                if liste[b][0]==f or liste[b][0]==g or liste[b-1][0]==g or liste[b-1][0]==f:
                    return True
        if a==3:
            if liste[b][0]==liste[b-1][0]==x :
                f=y+32
                g=y-32
                if liste[b][1]==f or liste[b][1]==g or liste[b-1][1]==g or liste[b-1][1]==f or liste[b-2][1]==g or liste[b-2][1]==f :
                    return True
            if liste[b][1]==liste[b-1][1]==y :
                f=x+32
                g=x-32
                if liste[b][0]==f or liste[b][0]==g or liste[b-1][0]==g or liste[b-1][0]==f or liste[b-2][0]==g or liste[b-2][0]==f:
                    return True
        if a==4:
            if liste[b][0]==liste[b-1][0]==x :
                f=y+32
                g=y-32
                if liste[b][1]==f or liste[b][1]==g or liste[b-1][1]==g or liste[b-1][1]==f or liste[b-2][1]==g or liste[b-2][1]==f or liste[b-3][1]==g or liste[b-3][1]==f:
                    return True
            if liste[b][1]==liste[b-1][1]==y :
                f=x+32
                g=x-32
                if liste[b][0]==f or liste[b][0]==g or liste[b-1][0]==g or liste[b-1][0]==f or liste[b-2][0]==g or liste[b-2][0]==f or liste[b-3][0]==g or liste[b-3][0]==f:
                    return True
     
    def bateau_joueur(event):
        global bateau_j
        if len(bateau_j)<17:
            x=(event.x//32)*32+29
            y=(event.y//32)*32+29
            if appartient_grille(x,y,2)==1:         #si x et y appartiennent à la grille 2, continuer
                if len(bateau_j)==0:                #premiere case du bateau de 2
                    g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                    bateau_j.append([x,y])
                if len(bateau_j)==1:                #deuxieme case du bateau de 2
                        if àcoté(x,y,1,0,bateau_j):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                            r=c.create_rectangle(500,357,600,377,fill="red")
                            bateau3=Label(fenetre, text='CHOISISSEZ VOTRE PREMIER BATEAU DE 3 CASES', bg='white', relief=GROOVE, font=police_b)
                            b3=c.create_window(368, 392, window=bateau3, height=25, width=352)
                if len(bateau_j)==2:                #premiere case du premier bateau de 3
                    if appartient_liste(x,y,2,bateau_j)==0:
                        g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                        bateau_j.append([x,y])
                if len(bateau_j)==3:                #deuxieme case du premier bateau de 3
                    if appartient_liste(x,y,3,bateau_j)==0:
                        if àcoté(x,y,1,2,bateau_j):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                if len(bateau_j)==4:                #troisieme case du premier bateau de 3
                    if appartient_liste(x,y,4,bateau_j)==0:
                        if àcoté(x,y,2,3,bateau_j):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                            r=c.create_rectangle(500,357,600,377,fill='white')
                            bateau3b=Label(fenetre, text='CHOISISSEZ VOTRE DEUXIEME BATEAU DE 3 CASES', bg='white', relief=GROOVE, font=police_b)
                            b3b=c.create_window(368, 392, window=bateau3b, height=25, width=352)
                if len(bateau_j)==5:                #premiere case du deuxieme bateau de 3
                    if appartient_liste(x,y,5,bateau_j)==0:
                        if bateau_possible(x,y,3):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                if len(bateau_j)==6:                #deuxieme case du deuxieme bateau de 3
                    if appartient_liste(x,y,6,bateau_j)==0:
                        if àcoté(x,y,1,5,bateau_j):
                            if bateau_possible(x,y,31):
                                g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                                bateau_j.append([x,y])
                if len(bateau_j)==7:                #troisieme case du deuxieme bateau de 3
                    if appartient_liste(x,y,7,bateau_j)==0:
                        if àcoté(x,y,2,6,bateau_j):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                            r=c.create_rectangle(500,357,600,377,fill='white')
                            bateau4=Label(fenetre, text='CHOISISSEZ VOTRE BATEAU DE 4 CASES', bg='white', relief=GROOVE, font=police_b)
                            b4=c.create_window(368, 392, window=bateau4, height=25, width=352)
                if len(bateau_j)==8:                #premiere case du bateau de 4
                    if appartient_liste(x,y,8,bateau_j)==0:
                        if bateau_possible(x,y,4):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                if len(bateau_j)==9:                #deuxieme case du bateau de 4
                    if appartient_liste(x,y,9,bateau_j)==0:
                        if àcoté(x,y,1,8,bateau_j):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                if len(bateau_j)==10:               #troisieme case du bateau de 4
                    if appartient_liste(x,y,10,bateau_j)==0:
                        if àcoté(x,y,2,9,bateau_j):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                if len(bateau_j)==11:               #quatrieme case du bateau de 4
                    if appartient_liste(x,y,11,bateau_j)==0:
                        if àcoté(x,y,3,10,bateau_j):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                            r=c.create_rectangle(500,357,600,377,fill='red')
                            bateau5=Label(fenetre, text='CHOISISSEZ VOTRE BATEAU DE 5 CASES', bg='white', relief=GROOVE, font=police_b)
                            b5=c.create_window(368, 392, window=bateau5, height=25, width=352)
                if len(bateau_j)==12:               #premier case du bateau de 5
                    if appartient_liste(x,y,12,bateau_j)==0:
                        if bateau_possible(x,y,5):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                if len(bateau_j)==13:               #deuxieme case du bateau de 5
                    if appartient_liste(x,y,13,bateau_j)==0:
                        if àcoté(x,y,1,12,bateau_j):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                if len(bateau_j)==14:               #troisieme case du bateau de 5
                    if appartient_liste(x,y,14,bateau_j)==0:
                        if àcoté(x,y,2,13,bateau_j):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                if len(bateau_j)==15:               #quatrieme case du bateau de 5
                    if appartient_liste(x,y,15,bateau_j)==0:
                        if àcoté(x,y,3,14,bateau_j):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                if len(bateau_j)==16:               #cinquieme case du bateau de 5
                    if appartient_liste(x,y,16,bateau_j)==0:
                        if àcoté(x,y,4,15,bateau_j):
                            g=c.create_rectangle(x-30, y-30, x+0, y+0, fill="green")
                            bateau_j.append([x,y])
                            joué=Label(fenetre, text='A VOUS DE JOUER !!!', bg='white', relief=GROOVE, font=police_b)
                            j=c.create_window(368, 392, window=joué, height=25, width=352)
        else: partie(event.x,event.y)
     
    def recommencer():
        fenetre.open
        fenetre.destroy()
     
    def menu():
        subprocess.call("start python menu.py")
        fenetre.destroy()
     
    def quitter():
        fenetre.destroy()
     
    grille_ordi=Label(fenetre, text='GRILLE ENNEMI', bg='white', relief=GROOVE, font=police_b)
    go=c.create_window(174, 365, window=grille_ordi, height=25, width=323)
     
    grille_joueur=Label(fenetre, text='VOTRE GRILLE', bg='white', relief=GROOVE, font=police_b)
    gj=c.create_window(558, 365, window=grille_joueur, height=25, width=323)
     
    bateau2=Label(fenetre, text='CHOISISSEZ VOTRE BATEAU DE 2 CASES', bg='white', relief=GROOVE, font=police_b)
    b2=c.create_window(368, 392, window=bateau2, height=25, width=352)
     
    retourner_menu=Button(fenetre, text='Menu', font=police_b, bg="blue", fg="white")
    rm=c.create_window(277, 417, window=retourner_menu, height=23, width=150)
     
    recommencer=Button(fenetre, text='Recommencer', font=police_b, bg="blue", fg="white", command=recommencer)
    re=c.create_window(457, 417, window=recommencer, height=23, width=150)
     
    quitter=Button(fenetre, text='Quitter', font=police_b, bg="blue", fg="white", command=quitter)
    re=c.create_window(368, 442, window=quitter, height=23, width=150)
     
    bateau_ordi()
     
    c.config(cursor="pirate")
     
    c.bind('<Button-1>',bateau_joueur)
    c.pack()
    fenetre.mainloop()
    Fichiers attachés Fichiers attachés

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 362
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 362
    Points : 36 894
    Points
    36 894
    Par défaut
    Salut,

    Citation Envoyé par zayo4 Voir le message
    je souhaiterai donc de l'aide pour ce bloquage pour clôturer le jeu (c'est notre dernière étape
    Le plus simple serait de tout regrouper en un seul script.

    Citation Envoyé par zayo4 Voir le message
    Il faudrait que je puisse passé du menu au jeu (facile) mais ensuite que je puisse réinitialiser le jeu et/ou repasser sur le menu (là je bloque)
    C'est un dialogue entre l'utilisateur et le programme qui met à jour l'affichage et modifie quelques variables globales pour refléter l'état du programme.
    La logique ressemble à ce bout de code:
    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
    import tkinter as tk
     
    root = tk.Tk()
     
    menu_frame = tk.Frame(root, width=300, height=300, bg='blue')
    jeu_frame = tk.Frame(root, width=300, height=300, bg='green')
     
    current_frame = menu_frame
     
    def do_switch():
        global current_frame
        current_frame.grid_remove()
        if current_frame == menu_frame:
            current_frame = jeu_frame
        else:
            current_frame = menu_frame
        current_frame.grid(row=0, column=0)
     
    btn = tk.Button(root, text='next', command=do_switch)
    current_frame.grid(row=0, column=0)
    btn.grid(row=1, column=0)
    tk.mainloop()
    à vous de l'adapter pour que çà réponde à vos besoins et d'adapter votre code.

    - W

Discussions similaires

  1. [XL-2007] automatisation passer a une autre cellule
    Par vincent007 dans le forum Excel
    Réponses: 7
    Dernier message: 19/12/2010, 15h26
  2. bouton flash pour passer a une autre image clé
    Par sarden dans le forum Flash
    Réponses: 1
    Dernier message: 20/07/2009, 14h58
  3. Savoir le temps passé sur une page avant de passer vers une autre page
    Par karimphp dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 04/09/2007, 23h57
  4. valider un form et passer a une autre page en un button
    Par porco dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 16/05/2007, 11h12
  5. Réponses: 7
    Dernier message: 13/12/2005, 16h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo