[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Extending Surface Class



ERName wrote:
Is it possible to extend the surface class? Every time I do the
surface ends up dieing somehow right after it is created... I may just
be doing it in the wrong way, though. The main point is to override
the __str__() method, so if you know another way besides extending
pygame.Surface, I'd be happy to hear it.


class ExtendedSurface(pygame.Surface):

    def __init__(self, surface, string):
        pygame.Surface.__init__(surface, surface.get_size()) #The docs
say to include a size, etc. but that just gives me "too many values to
unpack" errors.
        self.string = string

    def __str__(self):
        return self.string



Thanks!
Hi,

>>> class ExtendedSurface(pygame.Surface):
...     def __init__(self, string, *args, **kwds):
...         pygame.Surface.__init__(self, *args, **kwds)
...         self.string = string
... ... def __str__(self):
...         return self.string
...
>>> s = ExtendedSurface("Hello", (1,1))
>>> print s
Hello


Lenard Lindstrom