From: Joe Van Dyk Date: 2005-06-22T06:15:41+09:00 Subject: Re: tk canvas question On 6/21/05, Joe Van Dyk wrote: > On 6/21/05, Joe Van Dyk wrote: > > Hi, > > > > I'm drawing stuff on a TkCanvas. Essentially, a bunch of shapes that > > move around. I need to keep track of where each shape has been, so I > > can draw the shape's history if needed (a "slug track"). > > > > So every time a shape move, I store its position. When I want to view > > a shape's history, I draw a line connecting each stored position. > > > > I'm currently drawing all of these lines directly on to the main canvas. > > > > The problem is when I want to hide the history lines. There can be > > 400 shapes, and each of them could have thousands of lines that detail > > their previous history. Going through and deleting all the TkcLines > > is taking a very long time. > > > > Is there a way to "group" each shape's history lines and then be able > > to give one command that shows and hides the lines in that group? > > > > Thanks, > > Joe > > > Aha. I found something called TkcGroup. I'm having difficulties > figuring out how to remove and/or hide the canvas objects that are in > each group though. I found this code out there somewhere: #!/usr/bin/env ruby require "tk" canvas = TkCanvas.new grp = TkcGroup.new(canvas) grp.add(TkcRectangle.new(canvas, '1c', '2c', '3c', '3c', 'outline' => 'black', 'fill' => 'blue')) canvas.pack canvas.bind 'Enter' do grp.configure 'fill', 'red' end canvas.bind 'Leave' do grp.configure 'fill', 'green' end Tk.mainloop I think it's supposed to have the rectangle change colors when the cursor enters and leaves the canvas. But I don't see any color change occuring. Can someone confirm this for me please?