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
|
from tkinter import*
def droite():
global x, y, diapo
x=x+4
diapo=diapo+1
if diapo==2:
diapo=0
cadre.itemconfig(personnage,image=liste[diapo])
cadre.coords(personnage,x,y)
def gauche():
global x, y, diapo
x=x-4
diapo=diapo+1
if diapo==4:
diapo=2
cadre.itemconfig(personnage,image=liste[diapo])
cadre.coords(personnage,x,y)
def haut():
global y, x, diapo
y=y-4
diapo=diapo+1
if diapo==6:
diapo=4
cadre.itemconfig(personnage,image=liste[diapo])
cadre.coords(personnage,x,y)
def bas():
global y, x, diapo
y=y+4
diapo=diapo+1
if diapo==8:
diapo=6
cadre.itemconfig(personnage,image=liste[diapo])
cadre.coords(personnage,x,y)
def touche(evt):
if evt.keysym=="Right":
droite()
if evt.keysym=="Left":
gauche()
if evt.keysym=="Up":
haut()
if evt.keysym=="Down":
bas()
f=Tk()
f.title("Animation")
f.geometry()
diapo=0
x, y = 250, 250
cadre = Canvas (f, width =1000, height =1000, bg="white")
cadre.pack()
liste=[]
for i in range (0,8):
liste.append(PhotoImage(file='pacman'+str(i)+'.gif'))
personnage=cadre.create_image(x,y,image=liste[0]) # pose la première image
f.bind("<Key>",touche)
f.mainloop() |
Partager