help:problem using the RawPen class/turtle module.
alex
ale_xp at yahoo.com
Sun Apr 7 09:23:00 EDT 2002
>
> Hi,
> thank you for your reply,
>
> I tryied to type your code on my python command line
> and unfortunatly I have the same message.
> So well yes I think you are right, something's wrong
> in my configuration.
>
> It seems that it comes from the turtle.py module, I'll
> try to have a look at it(even if I'm not an expert of
> python modules),
> it seems strange to me that it doesn't work because
> it is in the standard distribution and of course I
> haven't changed it.
>
> I made a copy & paste of my little test.
>
>
> Python 2.2 (#1, Mar 9 2002, 18:21:48)
> [GCC 2.95.2 19991024 (release)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import turtle
> >>> import Tkinter
> >>> root=Tkinter.Tk()
> >>> c=Tkinter.Canvas(root)
> >>> c.pack(expand=1)
> >>> mypen=turtle.RawPen(c)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/local/lib/python2.2/lib-tk/turtle.py", line 16, in __init__
> self.reset()
> File "/usr/local/lib/python2.2/lib-tk/turtle.py", line 42, in reset
> self.clear()
> File "/usr/local/lib/python2.2/lib-tk/turtle.py", line 53, in clear
> self._draw_turtle()
> File "/usr/local/lib/python2.2/lib-tk/turtle.py", line 262, in _draw_turtle
> self._arrow = _canvas.create_line(x-dx,y+dy,x,y,
> AttributeError: 'NoneType' object has no attribute 'create_line'
>
>
> alex.
I think I've found the problem,
it seems that the call to
...
self._arrow = _canvas.create_line(x-dx,y+dy,x,y,
width=self._width,
arrow="last",
capstyle="round",
fill=self._color)
...
in the turtle.py ( _draw_turtle() method)
doesn't work because the _canvas to refer to is
the one in the 'self' instance,
so with the following change:
self._arrow = self._canvas.create_line(x-dx,y+dy,x,y,....
^^^^^
everything is ok.
Without it the _canvas refers to a global that it
isn't been initialized to a Canvas when there is a
call to the RawPen class.
ale><
More information about the Python-list
mailing list