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
| # Créé le 03/05/2015 en Python 3.2
from tkinter import*
#Création d'une zone de photo
def zone(fen,h,w,photo,pos):
if pos == 0:
frame = Frame(fen, height=h,width=w,borderwidth=2, relief=GROOVE)
frame.pack(side=LEFT)
if pos == 1:
frame = Frame(fen, height=h,width=w,borderwidth=2, relief=GROOVE)
frame.pack(side=RIGHT)
if pos==2:
frame = Frame(fen, height=h,width=w,borderwidth=2, relief=GROOVE)
frame.pack(side=BOTTOM)
if pos==3:
frame = Frame(fen, height=h,width=w,borderwidth=2, relief=GROOVE)
frame.pack(side=BOTTOM)
can = Canvas(frame,height=200,width=200,bg="white", borderwidth=2, relief=GROOVE)
can.create_image(100,100,image=photo)
can.pack()
return(can)
# Gestion de l'événement Clic gauche sur la zone graphique
def Clic(event):
# position du pointeur de la souris
X = event.x
Y = event.y
print(X,Y)
fen=Tk()
FP1 = PhotoImage(file="cheval1.gif")
frame1=zone(fen,50,50,FP1,0)
FP2 = PhotoImage(file="cheval2.gif")
frame2=zone(fen,50,50,FP2,1)
FP3 = PhotoImage(file="cheval3.gif")
frame3=zone(fen,50,50,FP3,2)
FP4 = PhotoImage(file="cheval4.gif")
frame4=zone(fen,50,50,FP4,3)
fen.bind('<Button-1>',Clic) # évévement clic gauche (press)
mainloop() |
Partager