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
| from tkinter import *
from random import*
#Fonction efface coccinelle
global img
def efface() :
Fond.delete(img)
return
#Fonction Deplacement
def depla(gd,hb):
global xc,yc
xc,yc=xc+gd,yc+hb
return
def butG() :
efface()
depla(-100,0)
img=Fond.create_image(xc,yc,image=F_cocG,anchor="nw")
#construction de la fenêtre
fen=Tk()
fen.title("Go !")
fen.geometry("1000x680")
Fond=Canvas(fen,width=1000,height=680,bg="#BBBBF9")
Fond.place(x=0,y=0)
#Chargement des imaaes coccinelles
F_cocG=PhotoImage(file="cocG.gif")
F_cocH=PhotoImage(file="cocH.gif")
#Mis en place des bouttons
#largeur 30=250 pixels
Gauche=Button(fen,width=30,height=2,bg='white',text="Gauche",command=butG)
Gauche.place(x=1,y=620)
#Position initiale de la coccinelle
xc=randint(1,1000)
yc=randint(1,630)
#print("xc=",xc)
#print("yc=",yc)
img=Fond.create_image(xc,yc,image=F_cocH,anchor="nw")
fen.mainloop() |
Partager