transparent rectangle in pygame

pygame, python-2.7

Solution

You can also use gfxdraw which has several options and accepts alpha in color.

You'll need to import:

import pygame.gfxdraw

And use with:

pygame.gfxdraw.box(screen, pygame.Rect(0,0,200,200), (100,0,0,127))

Problem

I am trying to draw simple semi-transparent rectangle in pygame. I have tried this code: ``` import pygame, sys,pygame.mixer pygame.init() size = (width, height) = (400, 400) screen = pygame.display.set_mode(size) screen.fill((255,255,255)) pygame.draw.rect(screen, (23, 100, 255, 50), (100,100,100,100),0) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() running = False ``` But as you can see, the rectangle is not semi-transparent. It's like I inserted the color 23, 100, 255, 255) rather than (23, 100, 255, 50).

Original source

Related problems