469,648 Members | 1,195 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,648 developers. It's quick & easy.

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

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

Jul 18 '05 #1
3 2240
Matthias wrote:
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
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

Jul 18 '05 #2
Thanks....that's what I need :))

Bye,

Matthias
Jul 18 '05 #3
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

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by dominic | last post: by
4 posts views Thread by Peter Otten | last post: by
5 posts views Thread by Andrew Poulos | last post: by
3 posts views Thread by moondaddy | last post: by
26 posts views Thread by Jon Davis | last post: by
2 posts views Thread by devnew | last post: by
7 posts views Thread by MartinRinehart | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.