pygame - Python access variable -
im new python , im trying pygame dont know how should this..
def addrect(x, y, width, height, color, surface): rect = pygame.rect(x, y, width, height) pygame.draw.rect(surface, color, rect) pygame.display.flip()
thats creating rectangles question how should access ractangles create ? im trying .
r1 = addrect(20, 40, 200, 200, (61, 61, 61), screen)
but when try move using
r1.move(10,10)
i error
r1.move(10,10) attributeerror: 'nonetype' object has no attribute 'move'
how should access ? thanks-
python functions have default return value of none
. since, don't have return statement in function, returns none
not have attribute move()
.
from the python docs
in fact, functions without return statement return value, albeit rather boring one. value called none (it’s built-in name).
>>> def testfunc(num): num += 2 >>> print testfunc(4) none
you need add return
statement return rect
variable.
def addrect(x, y, width, height, color, surface): rect = pygame.rect(x, y, width, height) pygame.draw.rect(surface, color, rect) pygame.display.flip() return rect
Comments
Post a Comment