Kworks
Kworks

Reputation: 793

Python 2.7.3 :AttributeError: 'NoneType' object has no attribute 'canvas'

I am just beginner with python and have started with python 2.7.3 Version.I have been following up with Think Python e-book.I am stuck at chapter 4 Case study: interface design where there is a program to draw lines.I get the following error when i run the given code.

> Execution:

C:\Users\dell\Desktop>python first.py
<swampy.TurtleWorld.Turtle object at 0x017A1650> 
Traceback (most recent call last):
  File "first.py", line 7, in <module>
    fd(bob,100)
  File "C:\Python27\lib\site-packages\swampy\TurtleWorld.py", line 186, in fd
    self.world.canvas.line([p1, p2], fill=self.pen_color)
AttributeError: 'NoneType' object has no attribute 'canvas'`

> Script

from swampy.TurtleWorld import *
world=TurtleWorld
bob=Turtle()
print bob
fd(bob,100)
lt(bob)
fd(bob,100)
wait_for_user()

Upvotes: 0

Views: 2673

Answers (1)

Pavel Anossov
Pavel Anossov

Reputation: 62908

You forgot to instantiate your TurtleWorld:

world = TurtleWorld()
                   ↑ these were missing

Upvotes: 6

Related Questions