AttributeError: 'function' object has no attribute 'line' when trying to create canvas line
Hello,
I've been trying to create a visual experiment, and when I test the code, I get the attribute error saying that the function doesn't have the attribute "line". This confuses me greatly since I know Canvas's functions should still work within other functions I'm creating!
Here is the parts of my code that are getting errors. The bold lines are the one its having issues with:
def drawTarget(x,y,orientation,cnvs,length=target_ll,angle=targetAngle): if orientation == "left": AngleX = cos(radians(90-angle)) * 0.5*length else: AngleX = cos(radians(90+angle)) * 0.5*length AngleY = sin(radians(90+angle)) * 0.5*length canvas.line(x-AngleX,y-AngleY,x+AngleX,y+AngleY) #determines target locations for left and right side if random.randint(0,1): var.targetPos = -target_distance #left side else: var.targetPos = target_distance #right side #actually drawing target drawTarget(var.targetPos,0,target_orientation,targetCanvas)
Anyone know why this is happening?
Comments
Hi,
The
Canvasobject that you're passing todrawTarget()is calledcnvs, notcanvas. (The namecanvasdoes exist, but it's a function that serves as an alias ofCanvas, and right now only exists for backwards compatibility.)Bottom line: If you call
cnvs.line()instead, then this particular error at least should disappear!Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!