SonoFratello
SonoFratello

Reputation: 23

Error in Turtle Module

#!usr/bin/env python
from turtle import Turtle
timmy = Turtle #A turtle called Timmy. 

pointA = None
pointB = None
backgroundColour = (255,255,255)
penColour = (0,0,0) #So I can just say penColour, as opposed to (0,0,0)
graphicsWindowHeight = 640
graphicsWindowWidth = 640
equation = str(input("What is the equation as y=mx+c?Do not use spaces, please, it messes up the            code"))
if len(equation) != 6:
    print("You have broken my code. It is not perfect") #Short explanation

#(equation[3]) is gradient, and (equation[5]) is y-intercept, and x-intercept is equation[5] / equation[3]

def calculateAndDrawLine(pointA, pointB):
    #CALCULATE WHAT TO DRAW
    #y = 10 here
    pointA = ((equation[3]/-10)+10)*32,0
    #y = -10 here
    pointB = ((equation[3]/-10)*-1)+10*32,640
    #DRAW IT
    timmy.pencolor(penColour)
    timmy.penwidth(10)
    timmy.pendown()
    timmy.setpos(pointA[0],pointA[1])
    timmy.seth(pointB[0],pointB[1])


def drawAxis():
    timmy.setpos(320,-640)
    timmy.pencolor(penColour)
    timmy.penwidth(10)
    timmy.seth(320,0)
    timmy.setpos(320,0)
    timmy.seth(320,-320)

drawAxis()
calculateAndDrawLine()

This is my code, and it's not finished yet. I am trying to get it to draw the line o the equation inputted, using turtle graphics. But when I run it, I get this error. Is there anything I can do?

Traceback (most recent call last):
  File "C:\Users\Adam Powell\Documents\Python\Line drawer.py", line 34, in <module>
drawAxis()
  File "C:\Users\Adam Powell\Documents\Python\Line drawer.py", line 27, in drawAxis
timmy.setpos(320,-640)
  File "C:\Python34\lib\turtle.py", line 1773, in goto
    self._goto(Vec2D(*x))
AttributeError: 'int' object has no attribute '_goto'

Upvotes: 1

Views: 1001

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121514

You need to create an instance of the Turtle object:

timmy = Turtle()

Note the () call part. Without the call, all methods on timmy are unbound and their self parameter is not provided automatically. As a result, you end up passing in 320 as self, and that doesn't work.

Upvotes: 3

Related Questions