tkinter, canvas, get color of image?

Bryan Oakley oakley at bardo.clearlight.com
Sun Apr 13 13:19:22 EDT 2008


skanemupp at yahoo.se wrote:
> mapq = PhotoImage(file = 'C:\Users\saftarn\Desktop\elmapovic.gif')
> w.create_image(10, 10, image = mapq, anchor = NW)
> 
> after doing this is there any possibility of getting the
> characteristics of the GIF-picture(or bitmap if i use that)?
> 
> it would be very helpfull if i for example could do something like
> canvas.getcolor(image, mouseclick.x,mouseclick.y) if u get the point.
> get the color of the image where i clicked.

The image isn't "painted" on the canvas, so to answer your specific 
question, no, you can't get the color of a pixel on the canvas in the 
way that you ask.

However, when you click on the canvas you can get the item that was 
clicked on and the x/y of the click. From that you can figure out which 
pixel of the image is under the cursor. And from that you can query the 
image for the color of a specific pixel.



More information about the Python-list mailing list