tkinter, canvas, get color of image?
Bryan Oakley
oakley at bardo.clearlight.com
Tue Apr 15 18:46:07 EDT 2008
skanemupp at yahoo.se wrote:
> On 13 Apr, 19:19, Bryan Oakley <oak... at bardo.clearlight.com> wrote:
>> skanem... 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.
>
>
> how do i get the item?
> http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_image-method
>
> with any of those methods?
>
> when i click the mouse i can get event.object u mean?
You can use find_closest to find the object closest to the x,y of the
event. You can also do find_withtag(tk.CURRENT) which returns the item
under the mouse pointer.
More information about the Python-list
mailing list