From: MENON Jean-Francois Date: 2003-05-21T11:15:44+09:00 Subject: Re: problem deleting item on a TkCanvas Phil Tomson wrote: > > I've got a TkCanvas where I initially draw a vertical line at the far left > of the canvas. I've bound the left mouse button such that when pressed a > new vertical line is drawn at that x location, and the old line is > _supposed_ to be erased (deleted). But the old line is not being deleted. > > Here's the code: > > require 'tk' > class SigWave > def initialize(root,signame) > @frame = TkFrame.new(root).pack('anchor' => 'e','padx'=>1,'pady'=>1) > @name = TkLabel.new(@frame){text "#{signame}"}.pack('side'=>'left') > @canvas = TkCanvas.new(@frame) > @canvas.configure 'height'=> 20 > @canvas.pack('side'=>'right', 'fill'=>'x') > @cursor=TkcLine.new(@canvas, 1,0,1,20).fill('blue') > @canvas.bind('1',proc{|e| draw_cursor(e.x) }) > draw_cursor(1) > end > > def draw_cursor(x) > @canvas.delete(@cursor) #<= this seems to do nothing use @cursor.delete instead ? > @cursor=TkcLine.new(@canvas, x,0,x,20).fill('blue') > end > end > > root = TkRoot.new() {title "Waveform" } > SigWave.new(root,'signame') > > Tk.mainloop > #end of code > > Am I doing the @canvas.delete correctly? > > Phil I would do a @cursor.coords(..);Tk.update instead. I noticed some memory problems when creating/deleting a big number of canvas items with ruby. regards, jf