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
|
#### deplacement d'objet sur le Canvas
def mousedown(event):
global x,y,Object,ID,coord_dic,coord_frame_dic,coord_dic_imgsupp
x,y=event.x,event.y
can.configure(cursor='draft_small')
Object=can.find_closest(x,y,halo=15)
ID=Object
if ID[0]==coord_dic[4]:
pass
else:
can.itemconfigure(Object,width=2)
can.lift(Object)
def mouseup(event):
global Object,coordcroix,x,y,listrect,CM,RM,coordmaster,ID,coord_dic
can.configure(cursor='tcross')
#if Object:
#Object=tk.NONE
if len(listrect)>0:
if ID[0]==listrect[4]:
X,Y=x+(listrect[2]-listrect[0]),y+(listrect[3]-listrect[1])
#print ID
can.delete(ID[0])
CM=can.create_rectangle(x,y,X,Y,width=2,outline='green',dash=(4,6))
listrect=(x,y,X,Y,CM)
can.itemconfigure(Object,width=1)
#print 'listrect',listrect
if len(coordmaster)>0:
if ID[0]==coordmaster[4]:
X,Y=x+(coordmaster[2]-coordmaster[0]),y+(coordmaster[3]-coordmaster[1])
#print ID
can.delete(ID[0])
RM=can.create_rectangle(x,y,X,Y,width=2,outline='blue',dash=(4,6))
coordmaster=(x,y,X,Y,RM)
can.itemconfigure(Object,width=1)
#print 'coormaster',coordmaster
if len(coordcroix)!=0:
for i in coordcroix:
if i[0]==ID[0]:
can.delete(ID[0])
ID=can.create_oval((event.x)-5,(event.y)-5,(event.x)+5,(event.y)+5,
outline='yellow',fill='yellow',width=2)
coordcroix.remove(i)
coordcroix.append((ID,event.x,event.y))
can.itemconfigure(Object,width=1)
#print 'coordcroix',coordcroix
def mousemove(event):
global x,y,Object,ID,coord_dic
x1,y1=event.x,event.y
dx,dy=x1-x,y1-y
if ID[0]==coord_dic[4]:
pass
else:
can.move(Object,dx,dy)
x,y=x1,y1
##Bind des action souris sur le canvas
can=tkinter.Canvas(....)
can.bind('<Button-1>',mousedown)
can.bind('<ButtonRelease-1>',mouseup)
can.bind('<B1-Motion>',mousemove) |
Partager