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

Discussion in 'Python' started by Matthias, Jun 2, 2004.

  1. Matthias

    Matthias Guest

    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
    Matthias, Jun 2, 2004
    #1
    1. Advertising

  2. Matthias

    Eric Brunel Guest

    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
    Eric Brunel, Jun 2, 2004
    #2
    1. Advertising

  3. Matthias

    Matthias Guest

    Thanks....that's what I need :))

    Bye,

    Matthias
    Matthias, Jun 2, 2004
    #3
  4. Automated web documentation generation

    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
    Brian Quinlan, Jun 2, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Askari
    Replies:
    2
    Views:
    707
    Askari
    Aug 30, 2004
  2. PhilC
    Replies:
    2
    Views:
    882
    PhilC
    Oct 25, 2004
  3. Kamaljeet Saini
    Replies:
    0
    Views:
    405
    Kamaljeet Saini
    Feb 13, 2009
  4. James Black
    Replies:
    0
    Views:
    400
    James Black
    May 28, 2006
  5. Replies:
    10
    Views:
    259
    Rick Johnson
    Mar 15, 2013
Loading...

Share This Page