""" 淡入淡出显示图形的两个函数, 注意,在显示的过程中没有进行事件检测 """ import pygame from time import sleep from pygame.locals import * def fade_in_image(screen,image): """淡入显示图像""" for a in range(0,256): image.set_alpha(a) screen.fill((0,0,0)) screen.blit(image,(0,0)) pygame.display.update() sleep(0.01) def fade_out_image(screen,image): """淡出显示图像""" for a in range(255,-1,-1): image.set_alpha(a) screen.fill((0,0,0)) screen.blit(image,(0,0)) pygame.display.update() sleep(0.01) if __name__ == "__main__": screen = pygame.display.set_mode((480,360)) cover = pygame.image.load("封面.png").convert() fade_in_image(screen,cover) fade_out_image(screen,cover)