Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

AttributeError: 'function' object has no attribute 'line' when trying to create canvas line

edited October 2019 in OpenSesame


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
		AngleX = cos(radians(90+angle)) * 0.5*length
	AngleY = sin(radians(90+angle)) * 0.5*length
#determines target locations for left and right side	
if random.randint(0,1):
	var.targetPos = -target_distance #left side
	var.targetPos = target_distance #right side
#actually drawing target	

Anyone know why this is happening?


  • Hi,

    The Canvas object that you're passing to drawTarget() is called cnvs, not canvas. (The name canvas does exist, but it's a function that serves as an alias of Canvas, and right now only exists for backwards compatibility.)

    Bottom line: If you call cnvs.line() instead, then this particular error at least should disappear!



Sign In or Register to comment.