drawing with the mouse with turtle

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Nov 12 20:05:42 EST 2010


On Fri, 12 Nov 2010 19:24:50 -0500, Brian Blais wrote:

> I'd like to draw on a turtle canvas, but use the mouse to direct the
> turtle.  I don't see a good way of getting the mouse coordinates and the
> button state.

I think the right way to do that is by creating an event handler to the 
turtle. These docs are for Python 2.7 turtle, but they may be applicable 
to older versions as well:

http://docs.python.org/library/turtle.html#turtle.ondrag

I quote:

    >>> turtle.ondrag(turtle.goto)

    Subsequently, clicking and dragging the Turtle will move it 
    across the screen thereby producing handdrawings (if pen is down).


That's probably all you need to do.



-- 
Steven



More information about the Python-list mailing list