drawing with the mouse with turtle

Brian Blais bblais at bryant.edu
Sat Nov 13 02:48:34 CET 2010


On Nov 12, 2010, at 8:05 PM, Steven D'Aprano wrote:

> 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.


that's what I tried first, with no luck.  I am on 2.6 on Mac OSX (Enthought distribution).  The following code:


import turtle

turtle.reset()
turtle.speed(0)
turtle.ondrag(turtle.goto)
turtle.pendown()

running it in ipython brings up a window, but clicking, dragging, or anything like that doesn't move the turtle or draw anything.  running it in just plain python brings up the window, but it instantly closes.  I added:  turtle.mainloop()

which keeps the window open, but the clicking or dragging still doesn't move the turtle or update the window in any way.

			
					bb
-- 
Brian Blais
bblais at bryant.edu
http://web.bryant.edu/~bblais
http://bblais.blogspot.com/






More information about the Python-list mailing list