rbc has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone one know of how to do a "rubber band" on a Tk::Canvas widget?

You know, one clicks and drags inside the canvas widget
making a rectangle and returning the geometery/xy-cooridnates
when one lifts the mouse button?

Replies are listed 'Best First'.
Re: Rubber band
by Anonymous Monk on Jun 22, 2002 at 04:26 UTC
    yes. you need to know how to draw something (easy, see the Tk::Canvas pod), and you need to know how to bind mouse events (also relatively easy, see the Tk::bind pod).

    Once you get a mouse down event, you should also get a pair of xy coordinates, and that'd be your x1,y1 for whatever you're drawing.

    Every time the mouse moves, you should get a pair of xy coordinates, which will be your x2,y2 for whatever you're drawing.

    That's all easy to do, the only thing to look out for is memory leaks. Be sure to resize whatever you're drawing, cause you don't wanna create a hundred and 20 of whatever you're drawing (you can, but then you'd have to delete all the old ones, it's just easier to resize).

    If you've created a tk app before (at least a basic one), it should take you about an 1-2 hours to get this done (i could do it in half an hour, but i'd need perl to do it ;).