[Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt)
Howard Lightstone
howard at eegsoftware.com
Tue Apr 7 21:49:05 CEST 2009
Here is a *dumb* example of what I think you want. It can be elaborated with
crosshairs, ring sizing, etc.
import PIL
import Image
import ImageTk
class data:
startx=0
starty=0
def startmotioncallback(event):
data.startx=event.x
data.starty=event.y
def motioncallback(event):
deltax=event.x-data.startx
deltay=event.y-data.starty
data.startx=event.x
data.starty=event.y
# should put some limits on where the cirle is moved
# left as exercise.....
data.cnv.move(data.ring,deltax,deltay)
def Demo(root):
# resize window
root.geometry('400x400+0+0')
data.root=root
# make a canvas
cnv=Canvas(root)
cnv.pack(expand=1,fill=BOTH)
data.cnv=cnv
img=Image.open('white dragon.png') # some image you have.....
data.img=ImageTk.PhotoImage(img)
data.photo=cnv.create_image(0,0,image=data.img,anchor='nw')
data.ring=cnv.create_oval((100,100,300,300))
cnv.bind("<B1-Motion>",motioncallback)
cnv.bind("<Button-1>",startmotioncallback)
root.mainloop()
if __name__ == '__main__':
root=Tk()
Demo(root)
More information about the Image-SIG
mailing list