相关配置:
Anaconda 4.2.0 (64-bit)
Python 3.5.2
在打包发布的时候要注意,需要把相关图片和音乐放在和.exe文件相同的目录下。
import sys
import pygame
# pygame.init()
pygame.mixer.init()
print("播放音乐1")
path = r"**.mp3"
path1 = r"**.jpg"
screen = pygame.display.set_mode([921, 576])
icon = pygame.image.load(path1).convert_alpha()
pygame.display.set_icon(icon)
background = pygame.image.load(path1).convert_alpha()
pygame.display.set_caption('音乐盒')
pygame.time.delay(1000)
pygame.mixer.music.load(path)
# pygame.mixer.music.play()
while 1:
if pygame.mixer.music.get_busy() == False:
print('is playing!')
pygame.mixer.music.play()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.blit(background, (0, 0))
pygame.display.update()
运行效果:
我曾经跨过山和大海,也穿过人山人海,我曾经拥有着的一切,转眼都飘散如烟,我曾经失落失望失掉所有方向,直到看见平凡才是唯一的答案。
——韩寒《平凡之路》