Python怎么添加背景音乐?Python添加背景音乐方法
时间:2022-10-26 22:19
今天小编为大家带来了Python添加背景音乐的方法,想知道怎么做的小伙伴来看看接下来的这篇文章吧,相信一定会帮到你们的。
Python怎么添加背景音乐?Python添加背景音乐方法
1、首先打开pycharm工具,选择File--->Settings,查看是否安装pygame;如果没有,需要安装;

2、然后在python项目指定文件夹下,新建python文件,输入文件名称并选择python file;

3、打开已新建的python文件,导入pygame第三方包;

4、将电脑上的mp3格式文件拷贝到文件下,赋值给url变量;

5、再调用pygame模块中的mixer.init()方法,进行初始化;

6、接着调用mixer.music.load()方法,加载音频路径文件;

7、调用mixer.music.play()方法,播放音频文件;

8、最后保存代码并运行python文件,可以查看到运行成功,需要登录提供的网站,进入查看效果。

谢谢大家阅读观看,希望本文能帮到大家!