PIL will not do this alone - PIL is an image management library without user interfaces - it has a show method that opens an external program that displays the image but does not bind to the Python process.
Therefore, in order for the user to interact with the image, you need to create a GUI program using one of the consolidated toolkits for use with Python - the better known are Tkinter, GTK and Qt4. Tkinter is interesting in that it comes with a preinstalled Windows Python installation and is therefore more accessible to users of this system. Windows users would have to download and install the gtk or qt libraries separately in order to be able to use your program if you decide to use other tools.
Here is a minimalist Tkinter example with a clickable image:
import Tkinter from PIL import Image, ImageTk from sys import argv window = Tkinter.Tk(className="bla") image = Image.open(argv[1] if len(argv) >=2 else "bla2.png") canvas = Tkinter.Canvas(window, width=image.size[0], height=image.size[1]) canvas.pack() image_tk = ImageTk.PhotoImage(image) canvas.create_image(image.size[0]//2, image.size[1]//2, image=image_tk) def callback(event): print "clicked at: ", event.x, event.y canvas.bind("<Button-1>", callback) Tkinter.mainloop()
source share