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
| from tkinter import *
import time
import os
fen=Tk()
fen.title("PAC-MAN : Le jeu")
w,h=1200,650
fen.geometry('1200x650')
fen.resizable(width=False, height=False) #enlever flèches aussi
fen.configure(background='#031792')
def game():
global w,h,item,stop
fen.iconify()
pacman=Toplevel(fen)
pacman.title("PAC-MAN : Le jeu")
pacman.configure(background='#031792')
d, f = pacman.winfo_screenwidth(), pacman.winfo_screenheight()
pacman.overrideredirect(1)
pacman.geometry("%dx%d+0+0" % (d, f)) ##pour plein écran
pacman.resizable(width=False, height=False)
test=Canvas(pacman,bg='black',bd=8,relief="groove",height=1000,width=1775)
test.config(highlightbackground='#031792')
test.grid(padx=60,pady=30)
Pacmanbase = PhotoImage(file= "pacmanbase.png")
item=test.create_image(w/2,h/2,image=Pacmanbase)
Pacmandroite_1 = PhotoImage(file = "pacman1r.png")
Pacmandroite_2 = PhotoImage(file = "pacman2r.png")
Pacmangauche_1 = PhotoImage(file = "pacman1l.png")
Pacmangauche_2 = PhotoImage(file = "pacman2l.png")
Pacmanbas_1 = PhotoImage(file = "pacman1d.png")
Pacmanbas_2 = PhotoImage(file = "pacman2d.png")
Pacmanhaut_1 = PhotoImage(file = "pacman1u.png")
Pacmanhaut_2 = PhotoImage(file = "pacman2u.png")
def gauche():
global item,x,y
test.itemconfig(item,image=Pacmangauche_1)
test.after(100,changeleft)
test.move(item,-10,0)
if stop==2:
droite()
elif stop==3:
haut()
elif stop==4:
bas()
else:
test.after(300,gauche)
def droite():
global item
test.itemconfig(item,image=Pacmandroite_1)
test.after(100,changeright)
test.move(item,+10,0)
if stop==1:
gauche()
elif stop==3:
haut()
elif stop==4:
bas()
else:
test.after(300,droite)
def haut():
global item
test.itemconfig(item,image=Pacmanhaut_1)
test.after(100,changeup)
test.move(item,0,-10)
if stop==2:
droite()
elif stop==1:
gauche()
elif stop==4:
bas()
else:
test.after(300,haut)
def bas():
global item
test.itemconfig(item,image=Pacmanbas_1)
test.after(100,changedown)
test.move(item,0,+10)
if stop==2:
droite()
elif stop==3:
haut()
elif stop==1:
gauche()
else:
test.after(300,bas)
def move(evt):
global item,stop
if evt.keysym=="Left":
stop=1
gauche()
elif evt.keysym=="Right":
stop=2
droite()
elif evt.keysym=="Up":
stop=3
haut()
else:
stop=4
bas()
def changebaseleft():
test.itemconfig(item,image=Pacmanbase)
test.after(100,left)
def changebaseright():
test.itemconfig(item,image=Pacmanbase)
test.after(100,right)
def changebasedown():
test.itemconfig(item,image=Pacmanbase)
test.after(100,down)
def changebaseup():
test.itemconfig(item,image=Pacmanbase)
test.after(100,up)
def left():
test.itemconfig(item,image=Pacmangauche_1)
def changeleft():
test.itemconfig(item,image=Pacmangauche_2)
test.after(100,changebaseleft)
def right():
test.itemconfig(item,image=Pacmandroite_1)
def changeright():
test.itemconfig(item,image=Pacmandroite_2)
test.after(100,changebaseright)
def up():
test.itemconfig(item,image=Pacmanhaut_1)
def changeup():
test.itemconfig(item,image=Pacmanhaut_2)
test.after(100,changebaseup)
def down():
test.itemconfig(item,image=Pacmanbas_1)
def changedown():
test.itemconfig(item,image=Pacmanbas_2)
test.after(100,changebasedown)
pacman.bind("<Left>",move)
pacman.bind("<Right>",move)
pacman.bind("<Up>",move)
pacman.bind("<Down>",move)
#w, h = fen.winfo_screenwidth(), fen.winfo_screenheight()
#fen.overrideredirect(1)
#fen.geometry("%dx%d+0+0" % (w, h)) ##pour plein écran
presentation=Label(fen,text="Bienvenue à vous dans l'interface d'accueil de notre projet d'Informatique et Sciences du Numérique ! \n Le long de notre année nous avons appris les bases de python, html, css et php.\n Mais nous avons été particulièrement attirés par la partie interface graphique. (Tkinter,canvas, ...)\n Nous avons donc décidé de créer un jeu et pas n'importe lequel : Pac-Man !")
presentation.config(font=('arial',18))
presentation.config(bg='#031792', fg='gold')
presentation.grid(padx=0, pady=0)
FOND = PhotoImage(file = "fond.gif") #image
can=Canvas(fen,bg='black',bd=8,relief="ridge",height=350,width=800) #largeur et hauteur du cadre noir
can.config(highlightbackground='#031792')
can.create_image(700,195,image=FOND)
can.grid(padx=100,pady=30) #emplacement du cadre noir
start = PhotoImage(file='start.png')
bt_jouer=Button(fen, image=start,command=game) #BOUTON START
bt_jouer_fen=can.create_window(200,190,window=bt_jouer) #commande trouvée sur internet pour que le bouton soit dans le canvas
ind = -1 #pour que le gif fonctionne
def update(delay=50):
global ind
ind += 1
if ind == 8: ind = 5
print (ind)
FOND.configure(format="gif -index " + str(ind))
fen.after(delay, update)
update()
quit=Button(fen,text="Quitter",command=fen.destroy) # BOUTON QUITTER
quit.grid(padx=w/2 ,pady=10)
fen.mainloop() |
Partager