transp_rectangle.py 872 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from pygame.locals import *
  4. import pygame
  5. pygame.init()
  6. # Resolution
  7. WIDTH = 800
  8. HEIGHT = 500
  9. # Colors
  10. BLUE = ((0, 0, 255))
  11. RED = ((255, 0, 0))
  12. screen = pygame.display.set_mode((WIDTH, HEIGHT))
  13. pygame.display.set_caption('Transparent rectangle')
  14. screen.fill(BLUE)
  15. font = pygame.font.Font('freesansbold.ttf', 22)
  16. text_surf = font.render('Text', True, RED)
  17. text_rect = text_surf.get_rect()
  18. text_rect.center = (WIDTH / 2, HEIGHT / 2)
  19. screen.blit(text_surf, text_rect)
  20. surface = pygame.Surface((100, 60))
  21. surface.set_alpha(200)
  22. surface_rect = surface.get_rect()
  23. surface_rect.center = (WIDTH / 2, HEIGHT / 2)
  24. screen.blit(surface, surface_rect)
  25. running = True
  26. while running:
  27. pygame.display.update()
  28. for event in pygame.event.get():
  29. if event.type == QUIT:
  30. pygame.quit()
  31. running = False