Canvas-Widget .... Color at position x,y

M

Matthias

Hello,

I have a Canvas-Widget and will use as a "array of pixel". At Positon
x,y I print a rectangle with a special color. I give the rectangle no
objectname. Then I will ask the "root-Canvas-Widget" for the color in
position x,y like:

color=cw.cget('bg',x,y)

I need HELP :))

Bye

Matthias
 
E

Eric Brunel

Matthias said:
Hello,

I have a Canvas-Widget and will use as a "array of pixel". At Positon
x,y I print a rectangle with a special color. I give the rectangle no
objectname. Then I will ask the "root-Canvas-Widget" for the color in
position x,y like:

color=cw.cget('bg',x,y)

I need HELP :))

You can get the tags for the objects at position (x, y) via:
tags = cw.find_overlapping(x, y, x, y)
(or maybe cw.find_overlapping(x, y, x+1, y+1); I didn't test...)
If you're sure you've got only one object overlapping this position, you can
then do:
color = cw.itemcget(tags[0], 'bg')

BTW, using a Canvas as an array of pixels does not seem like a good idea to me:
canvases are intended to do vector drawing, not bitmap...

Are you aware that you can do what you want via images? Example:

--images.py---------------------
from Tkinter import *

root = Tk()
cnv = Canvas(root)
cnv.pack(side=TOP)
img = PhotoImage(width=100, height=100)
cnv.create_image(0, 0, anchor=NW, image=img)

def plot():
for i in range(10, 90):
img.put('#ff0000', to=(i, i))
img.put('#00ff00', to=(i, 100 - i))

def read():
for i in range(0, 100):
print img.get(i, 40)

Button(root, text='Plot', command=plot).pack(side=LEFT)
Button(root, text='Read', command=read).pack(side=LEFT)

root.mainloop()
--------------------------------

This is much easier to do (except maybe for the strange format of the color
returned by img.get) and images are intended for this purpose, so you're less
likely to have any problem.

HTH
 
B

Brian Quinlan

I'm looking for a way to serve Python source documentation on our
company's intranet. Pydoc-style documentation would be great, but the
following features (that Pydoc lacks) would great:

o hostable as CGI (this is the most important)
o separation between library modules, site-packages modules and other
modules
o searchable
o dynamic document generation i.e. no static HTML pages

Does anyone know of a system with similar properties?

Cheers,
Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top