require 'tk' class TkMove def initialize( canvas, tag ) canvas.itembind(tag,'1',proc{|x,y| self.plotDown canvas, x, y }, "%x %y") canvas.itembind(tag, 'B1-Motion',proc{|x,y| self.plotMove canvas, x, y }, "%x %y") @lastx, @lasty = 0, 0 end def plotDown (w, x, y) w.dtag 'selected' w.addtag_withtag 'selected', 'current' w.raise 'current' @lastx, @lasty = x, y end def plotMove (w, x, y) w.move 'selected', x - @lastx, y - @lasty @lastx, @lasty = x, y end end c = TkCanvas.new.pack m = TkMove.new(c, 'circle') c.itembind('circle','Any-Enter',proc{c.itemconfigure 'current','fill','blue'}) c.itembind('circle','Any-Leave',proc{c.itemconfigure 'current','fill','red'}) TkcOval.new(c, 130, 70, 160, 100, 'fill'=>'red').addtag('circle') Tk.mainloop