Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Canvas-Widget .... Color at position x,y

Reply
Thread Tools

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

 
 
Matthias
Guest
Posts: n/a
 
      06-02-2004
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

 
Reply With Quote
 
 
 
 
Eric Brunel
Guest
Posts: n/a
 
      06-02-2004
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

 
Reply With Quote
 
 
 
 
Matthias
Guest
Posts: n/a
 
      06-02-2004
Thanks....that's what I need )

Bye,

Matthias
 
Reply With Quote
 
Brian Quinlan
Guest
Posts: n/a
 
      06-02-2004
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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing font color from current font color to black color Kamaljeet Saini Ruby 0 02-13-2009 04:58 PM
detecting mouse click position in canvas tag has position off James Black Javascript 0 05-28-2006 03:27 AM
Where is Form Relative Position and Absolute Position in VS.Net 2005 ? Luqman ASP .Net 1 02-07-2006 10:27 AM
position image based on document position edouard.lauer@pt.lu Javascript 3 01-14-2006 06:04 PM
How to set position of a web control depending on other control's position at run-time? James Wong ASP .Net Web Controls 4 07-14-2004 10:24 AM



Advertisments