| 12
 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
 
 | from tkinter import *
from random import randrange
 
# Création de la commande Echap
def clavier(event):
    global coords
    touche = event.keysym
 
    can.delete(ALL)
 
    sprite_wall = can.create_image(0, 0, anchor = NW, image = fond)
 
    cmd = [[270, 450, bexit, "quitt", quitt],
           [270, 400, bcont, "bcont", cont],
           [270, 350, bstart, "bstart", start]]
 
    for elt in cmd :
        can.create_image(elt[0], elt[1], image=elt[2], tag=elt[3])
        can.tag_bind(elt[3], "<Button-1>", elt[4])
 
    fen1.mainloop()
 
 
#Fonction quitter   
def quitt(event):
 
    fen1.destroy()
 
#Fonction du menu controls
def cont(event):
    can.delete(ALL)
 
    can.create_image(0, 0, anchor = NW, image = photo)
    can.focus_set()
    can.bind("<Escape>", clavier)
 
    fen1.mainloop()
 
#niveau 1
def niv1(event):
    can.delete(ALL)
    x,y=0,0
    level1=can.create_image(x,y, image=photoniv1)
 
    fen1.bind("<Right>", droite)
    fen1.bind("<Left>", gauche)
 
 
    fen1.mainloop()
 
def droite(event) :
 global x
 
 
 x=x+5
 can.coords(level1,x,y)
 can.itemconfig(level1,image=photoniv1)
 
 
def gauche(event) :
 global x
 
 
 x=x-5
 can.coords(level1,x,y)
 can.itemconfig(level1,image=photoniv1)
 
 
 
 
 
#menu start
def start(event):
    can.delete(ALL)
 
    can.create_image(0, 0, anchor = NW, image = fondniveauselect)
 
#Creation des boutons de niveaux
    cmd = [[100, 100, bniv1, "bniv1"],
           [270, 100, bniv2, "bniv2"],
           [440, 100, bniv3, "bniv3"],
           [100, 270, bniv4, "bniv4"],
           [270, 270, bniv5, "bniv5"],
           [440, 270, bniv6, "bniv6"],
           [100, 440, bniv7, "bniv7"],
           [270, 440, bniv8, "bniv8"],
           [440, 440, bniv9, "bniv9"]]
 
    for elt in cmd :
        can.create_image(elt[0], elt[1], image=elt[2], tag=elt[3])
        can.tag_bind(elt[3], "<Button-1>", niv1)
 
 
    can.focus_set()
    can.bind("<Escape>", clavier)
 
    fen1.mainloop()
 
 
 
#Creation de la fenetre
fen1 = Tk()
#Creation du titre de la fenetre
fen1.title('Les Bros')
 
#Importation des images
fond = PhotoImage(file="menu.gif")
bexit = PhotoImage (file="exit.gif")
bcont = PhotoImage (file="controls.gif")
bstart = PhotoImage (file="startgame.gif")
photo = PhotoImage(file="fondcontrols.gif")
photoniv1 = PhotoImage(file="niveau1.gif")
fondniveauselect = PhotoImage(file="fondniveauselect.gif")
bniv1 = PhotoImage (file="selectniv1.gif")
bniv2 = PhotoImage (file="selectniv2.gif")
bniv3 = PhotoImage (file="selectniv3.gif")
bniv4 = PhotoImage (file="selectniv4.gif")
bniv5 = PhotoImage (file="selectniv5.gif")
bniv6 = PhotoImage (file="selectniv6.gif")
bniv7 = PhotoImage (file="selectniv7.gif")
bniv8 = PhotoImage (file="selectniv8.gif")
bniv9 = PhotoImage (file="selectniv9.gif")
 
#Creation du canvas principal
can = Canvas(fen1, width = 540, height = 540)
can.pack()
 
sprite_wall = can.create_image(0, 0, anchor = NW, image = fond)
 
 
#Creation des boutons principaux
cmd = [[270, 450, bexit, "quitt", quitt],
       [270, 400, bcont, "bcont", cont],
       [270, 350, bstart, "bstart", start]]
 
for elt in cmd :
    can.create_image(elt[0], elt[1], image=elt[2], tag=elt[3])
    can.tag_bind(elt[3], "<Button-1>", elt[4])
 
 
 
 
fen1.mainloop() |