Posted to tcl by kbk at Fri Feb 25 20:13:39 GMT 2011view pretty
proc startSelection {x y} { variable xstart variable ystart set xstart [.c canvasx $x] set ystart [.c canvasy $y] .c create rectangle $xstart $ystart $xstart $ystart -tags selector \ -outline green -dash - -fill {} } proc adjustSelection {x y} { variable xstart variable ystart set x [.c canvasx $x] set y [.c canvasy $y] .c coords selector $xstart $ystart $x $y return [list $xstart $ystart $x $y] } proc endSelection {x y b} { lassign [adjustSelection $x $y] x0 y0 x1 y1 .c delete selector # At this point you probably want to do [.c find overlapping $x0 $y0 $x1 $y1] and # do something with the result. } bind .c <ButtonPress-1> [list startSelection %x %y] bind .c <B1-Motion> [list adjustSelection %x %y] bind .c <ButtonRelease-1> [list endSelection %x %y %b]