SNIP IT: tk.Canvas Drag Items Around

Fredrik Lundh fredrik at pythonware.com
Thu Jun 20 03:50:23 EDT 2002


"Phlip" wrote:

>     points = event.widget.coords (tk.CURRENT)
>     anchors = copy.copy(points[:2])
>     print points
>
>     for idx in range(len(points)):
> #        print idx, xy[idx % 2], anchors[idx % 2]
>         mouse = xy[idx % 2]
>         zone = anchors[idx % 2]
>         points[idx] = points[idx] - zone + mouse
>
>     print points
>     apply(event.widget.coords, [tk.CURRENT] + points)

footnote: the canvas provides a nice little method called "move"
that adds X and Y offsets to all coordinates of all matching items:

    dx = mouse[0] - anchors[0]
    dy = mouse[1] - anchors[1]
    event.widget.move(tk.CURRENT, dx, dy)

for more info, see

http://www.pythonware.com/library/tkinter/introduction/canvas.htm
=> Methods

</F>





More information about the Python-list mailing list