473,472 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2362
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dominic | last post by:
Hi all, I was referring to http://forum.java.sun.com/thread.jsp?forum=57&thread=204595 to handle the resizing problem. So I put the canvas into a JScrollPane, and then add the pane into the...
4
by: Peter Otten | last post by:
Is there a way to limit both width and height of a canvas text item? My current workaround seems clumsy: import Tkinter as tk root = tk.Tk() canvas = tk.Canvas(root, width=400, height=200,...
1
by: Mudcat | last post by:
I have an image that displays on a canvas that works unless I put the same code in a class. I can't figure that out. Here's what works: def uts5100(self): self.screen = Toplevel( self.master )...
0
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the...
5
by: Andrew Poulos | last post by:
Is there a right/best way to draw an ellipse using Canvas? (With VML there's the v:oval element which makes the exercise trivial). I tried drawing a 360 degree arc (a circle) and then scaling it...
3
by: moondaddy | last post by:
I'm working in a WPF windows application and am wondering if it's possible to rotate a Canvas or user control derived from Canvas. I created a user control which derives from Canvas and I need to...
26
by: Jon Davis | last post by:
OK, why is Canvas not IDisposable, and how do I get rid of all the Windows handles? I'm doing a performance test of looping through a dynamic XAML-to-JPEG conversion. It gets to about 500...
2
by: devnew | last post by:
hi i am new to tkinter and would like some help with canvas i am doing validation of contents of a folder and need to show the ok/error messages on a canvas resultdisplay =Canvas(...)...
4
by: moondaddy | last post by:
I have a wpf project where I use a canvas to drag shapes around. when I drag a shape beyond the right or bottom side I get scrollbars which is good. I also get scrollbars when I zoom in and a...
7
by: MartinRinehart | last post by:
In the bit of code posted below, I get a 256x128 canvas, sized via CSS. Then I write a color wash, same dimensions. Problem: wash is about 10% smaller than the canvas. Results identical, FF on...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.