Search code examples
pythontransparencypygame

How to make a surface with a transparent background in pygame


Can someone give me some example code that creates a surface with a transparent background in pygame?


Solution

  • This should do it:

    image = pygame.Surface([640,480], pygame.SRCALPHA, 32)
    image = image.convert_alpha()
    

    Make sure that the color depth (32) stays explicitly set else this will not work.