Python NameError: name 'self' not defined Why?
At the top :
import pygame, sys
from pygame.sprite import Sprite
from pygame.locals import *
pygame.init()
Part doesn't work :
class DetectionBox(Sprite):
def __init__(self):
Sprite.__init__(self)
self.img = pygame.Surface([SCREEN_WIDTH, SCREEN_HEIGHT/4], SRCALPHA, 32).convert_alpha()
self.pos = (0, SCREEN_HEIGHT - (SCREEN_HEIGHT/4)*3)
DETECT_BOX = DetectionBox()
Error : NameError: name 'self' is not defined
Someone please explain why this doesn't work because I have no idea. It works correctly with all other classes, so this is something about it.
+3
source to share