**
例:
**
import os
import pygame
# 初始化Pygame
pygame.init()
# 初始化Mixer模块
pygame.mixer.init()
# 获取当前可执行文件的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建音乐文件的绝对路径
audio_path = os.path.join(current_dir, 'abc.mp3')
# 加载音乐文件
pygame.mixer.music.load(audio_path)
# 设置音乐循环播放
pygame.mixer.music.play(loops=-1)
# 保持程序运行
try:
while True:
# 可以在这里添加其他代码,例如处理事件
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
except KeyboardInterrupt:
# 按Ctrl+C退出程序
pass
文件位置:
在当前文件下面打开powershell,输入 pyinstaller -F --noconsole -i favicon.ico ceshi.py --add-data="abc.mp3;."
运行完成后在生成的dist文件下可看到生成的exe文件。