import pygame
import sys
from pygame.locals import*
import random
import time
# 初始化
pygame.init()
screen = pygame.display.set_mode((500, 500))
pygame.display.set_caption("祝你生日快乐")
font = pygame.font.Font("yangrendong.ttf", 50)
pygame.mixer.music.load("生日快乐.mp3")
pygame.mixer.music.set_volume(0.2)
pygame.mixer.music.play(-1)
screen.fill((250, 248, 236))
pygame.display.update()
s = "嗨,某某某:今天是你的11岁生日,转眼之间,我们已经认识4年了。祝你生日快乐,平平安安。新的一岁,新的开始,一起加油吧! "
flag = 0
# 主循环
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
screen.fill((250, 248, 236))
font = pygame.font.Font("yangrendong.ttf", 50)
text = font.render("生日快乐!", True, (255, 0, 0), (250, 248, 236))
screen.blit(text, (160, 200))
pygame.display.update()
pygame.time.wait(2000)
pygame.quit()
sys.exit()
pos = [0,0]
if flag == 0:
for i in range(6):
for things in pygame.event.get():
if things.type == pygame.QUIT:
screen.fill((250, 248, 236))
font = pygame.font.Font("yangrendong.ttf", 50)
text = font.render("生日快乐!", True, (255, 0, 0), (250, 248, 236))
screen.blit(text, (160, 200))
pygame.display.update()
pygame.time.wait(2000)
pygame.quit()
sys.exit()
font = pygame.font.Font("yangrendong.ttf", 25)
text = font.render(s[i], True, (random.randint(0,230),random.randint(0,230),random.randint(0,230)),(250, 248, 236))
screen.blit(text, (pos[0],pos[1]))
pygame.display.update()
pygame.time.wait(250)
pos[0] += 50
flag = 1
pos[0] = 0
pos[1] = 25
for i in range(7):
for j in range(10):
for things in pygame.event.get():
if things.type == pygame.QUIT:
screen.fill((250, 248, 236))
font = pygame.font.Font("yangrendong.ttf", 50)
text = font.render("生日快乐!", True, (random.randint(0,230),random.randint(0,230),random.randint(0,230)), (250, 248, 236))
screen.blit(text, (160, 200))
pygame.display.update()
pygame.time.wait(2000)
pygame.quit()
sys.exit()
font = pygame.font.Font("yangrendong.ttf", 25)
text = font.render(s[i*10+j + 6], True, (random.randint(0,230),random.randint(0,230),random.randint(0,230)),(250, 248, 236))
screen.blit(text, (pos[0],pos[1]))
pos[0] += 50
pygame.display.update()
pygame.time.wait(250)
pos[1] += 50
pos[0] = 0
flag = 1
pygame.display.update() # 更新
编辑不易,求个点赞!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!