How to make a surface with a transparent background in pygame

Paul D. Eden picture Paul D. Eden · Nov 29, 2008 · Viewed 29.7k times · Source

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

Answer

UnkwnTech picture UnkwnTech · Nov 29, 2008

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.