Thank you all,<br>Peter Otten&#39;s patch worked right off the bat. Now that Peter explained the core of the problem I&#39;ll be able to tinker with the code to dig deeper.<br>Steve<br><br><div class="gmail_quote">On Mon, Oct 17, 2011 at 3:00 AM,  <span dir="ltr">&lt;<a href="mailto:tkinter-discuss-request@python.org">tkinter-discuss-request@python.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Send Tkinter-discuss mailing list submissions to<br>
        <a href="mailto:tkinter-discuss@python.org">tkinter-discuss@python.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://mail.python.org/mailman/listinfo/tkinter-discuss" target="_blank">http://mail.python.org/mailman/listinfo/tkinter-discuss</a><br>
or, via email, send a message with subject or body &#39;help&#39; to<br>
        <a href="mailto:tkinter-discuss-request@python.org">tkinter-discuss-request@python.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:tkinter-discuss-owner@python.org">tkinter-discuss-owner@python.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of Tkinter-discuss digest...&quot;<br>
<br>
<br>
Today&#39;s Topics:<br>
<br>
   1. Re: Limit to the number of canvases in a  top_level object?<br>
      (Peter Otten)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Sun, 16 Oct 2011 15:43:26 +0200<br>
From: Peter Otten &lt;__<a href="mailto:peter__@web.de">peter__@web.de</a>&gt;<br>
To: <a href="mailto:tkinter-discuss@python.org">tkinter-discuss@python.org</a><br>
Subject: Re: [Tkinter-discuss] Limit to the number of canvases in a<br>
        top_level object?<br>
Message-ID: &lt;j7emvl$m7$<a href="mailto:1@dough.gmane.org">1@dough.gmane.org</a>&gt;<br>
Content-Type: text/plain; charset=&quot;ISO-8859-1&quot;<br>
<br>
Steve Solomon wrote:<br>
<br>
&gt;&gt;&gt; Is there  a limit to the number of canvases in a top_level object -- one<br>
&gt;&gt;&gt; maybe ? I have been trying to solve this problem with an application for<br>
&gt;&gt;&gt; several weeks. In the application I have two canvases, each with a grid<br>
&gt;&gt;&gt; of rectangle objects. They display perfectly but when I try to interact<br>
&gt;&gt;&gt; with the rectangles they behave anomalously. Using<br>
&gt;&gt;&gt; canvas.find_closest(event.x, event.y) the rectangles in the first drawn<br>
&gt;&gt;&gt; canvas behave normally, allowing configuring each, but within the second<br>
&gt;&gt;&gt; canvas the rectangles report back the id of only one of the rectangles<br>
&gt;&gt;&gt; and an attempt to change the fill-color of any one is applied only to<br>
&gt;&gt;&gt; the last item in the grid.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Your thoughts would be appreciated, thank you<br>
<br>
&gt; I&#39;m a bit in the tall weeds, please excuse the mess (in the attached<br>
&gt; code).<br>
<br>
The best time to clean up your code is always right now; the second best<br>
time is when you run into an error ;)<br>
<br>
&gt; from Tkinter import *<br>
&gt; import random<br>
&gt; import palettebuilder as pb<br>
&gt; from colorservices import getHSV<br>
&gt;<br>
&gt; def randomColors(count=1, sorted=False):<br>
&gt;     &quot;returns list of color strings in #nnnnnn hexidecimal format&quot;<br>
&gt;     rtn = []<br>
&gt;     for x in range(count):<br>
&gt;         intgr = random.randrange(0, 16777215, 1)<br>
&gt;         hex = &quot;#{:0&gt;6X}&quot;.format(intgr)<br>
&gt;         rtn.append(hex)<br>
&gt;     if sorted:<br>
&gt;         &quot;the folowing should be sorted by ...&quot;<br>
&gt; #        rtn.sort(key=lambda rtn: getHSV(rtn)[2]) #...value<br>
&gt;         rtn.sort(key=lambda rtn: getHSV(rtn)) #...full HSV<br>
&gt;     return rtn<br>
&gt;<br>
&gt; class test(Toplevel):<br>
&gt;     def __init__(self):<br>
&gt;         Toplevel.__init__(self)<br>
&gt;         self.config(height = 500, width = 500)<br>
&gt;         self.activeCanvas = None<br>
&gt;         self.bind(&quot;&lt;KeyPress-c&gt;&quot;, self.reportXY)<br>
&gt;         size = 180<br>
&gt;         frameOne = Frame(self, height = 200, width =200, bg = &quot;pink&quot;)<br>
&gt;         self.canvasOne = Canvas(frameOne, height=size, width=size,<br>
background=&quot;#bababa&quot;)<br>
&gt;         self.canvasOne.grid(row = 0, column = 0, sticky = W )<br>
&gt;         frameTwo = Frame(self, height = 200, width =200, bg=&quot;light blue&quot;)<br>
&gt;         self.canvasTwo = Canvas(frameTwo, height=size, width=size,<br>
bg=&#39;#bababa&#39;)<br>
&gt;         self.canvasTwo.grid(row = 1, column = 1)<br>
&gt;         self.canvasOne.bind(&quot;&lt;Enter&gt;&quot;, self.makeOneActive)<br>
&gt;         self.canvasTwo.bind(&quot;&lt;Enter&gt;&quot;, self.makeTwoActive)<br>
&gt;         frameOne.grid(row = 0, column = 0, sticky = W )<br>
&gt;         frameTwo.grid(row = 1, column = 1, sticky = E )<br>
&gt;         colors = randomColors(64, sorted = True)<br>
&gt;         pb.DrawPalette(self.canvasOne, colors, columns = 8)<br>
&gt;         colors = randomColors(64, sorted = True)<br>
&gt;         pb.DrawPalette(self.canvasTwo, colors, columns = 8)<br>
&gt;<br>
&gt;     def makeOneActive(self, event):<br>
&gt;         self.activeCanvas = self.canvasOne<br>
&gt;         print &quot;one = active self.activeCanvas&gt;&gt;&gt;&quot;, type(self.activeCanvas)<br>
&gt;<br>
&gt;     def makeTwoActive(self, event):<br>
&gt;         self.activeCanvas = self.canvasTwo<br>
&gt;         print &quot;two = active self.activeCanvas&gt;&gt;&gt;&quot;, type(self.activeCanvas)<br>
&gt;<br>
&gt;     def reportXY(self, event):<br>
&gt;         print event.x, event.y<br>
&gt;         item=self.activeCanvas.find_closest(event.x, event.y)<br>
&gt;         print self.activeCanvas.itemcget(item, &quot;tags&quot;), &quot;item&gt;&gt;&quot;, item<br>
&gt;         self.activeCanvas.itemconfigure(item, fill = &quot;red&quot;)<br>
&gt;<br>
&gt; root = Tk()<br>
&gt; root.withdraw()<br>
&gt; test()<br>
&gt; #for x in range(10):<br>
&gt; #    print randomColors(10)<br>
&gt; #    print &quot;\n&quot;<br>
&gt; root.mainloop()<br>
&gt;<br>
<br>
You bind the reportXY() method to an event triggered by your Toplevel<br>
subclass, so the event instance contains coordinates relative to the test<br>
widget. On the other hand the Canvas.find_closest() method expects<br>
coordinates in terms of the canvas widget. The difference doesn&#39;t matter for<br>
canvasOne which is located at the origin of the toplevel, but gives wrong<br>
results for canvasTwo with its non-zero offset.<br>
<br>
While the diagnosis was easy it took me a while to find a way to convert<br>
between the two coordinate systems. The following seems to work:<br>
<br>
    def reportXY(self, event):<br>
        canvas = self.activeCanvas<br>
<br>
        dx = self.winfo_rootx() - canvas.winfo_rootx()<br>
        dy = self.winfo_rooty() - canvas.winfo_rooty()<br>
<br>
        x = event.x + dx<br>
        y = event.y + dy<br>
<br>
        print &quot;before&quot;, event.x, event.y<br>
        print &quot;after&quot;, x, y<br>
<br>
        item = canvas.find_closest(x, y)<br>
        print canvas.itemcget(item, &quot;tags&quot;), &quot;item&gt;&gt;&quot;, item<br>
        canvas.itemconfigure(item, fill=&quot;red&quot;)<br>
<br>
Let me know if you find a better way or run into a problem with my approach.<br>
<br>
<br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
Tkinter-discuss mailing list<br>
<a href="mailto:Tkinter-discuss@python.org">Tkinter-discuss@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/tkinter-discuss" target="_blank">http://mail.python.org/mailman/listinfo/tkinter-discuss</a><br>
<br>
<br>
End of Tkinter-discuss Digest, Vol 92, Issue 7<br>
**********************************************<br>
</blockquote></div><br>