python开发简易版在线音乐播放器

作者:whaben 时间:2022-08-29 14:38:29 

在线音乐播放器,使用python的Tkinter库做了一个界面,感觉这个库使用起来还是挺方便的,音乐的数据来自网易云音乐的一个接口,通过urllib.urlopen模块打开网址,使用Json模块进行数据的解析,最后使用mp3play库对音乐进行在线播放,也可以同时下载mp3,开发环境:python2.7,附上源代码如下:


# _*_ coding:utf-8 _*_
from Tkinter import *
import tkMessageBox
import urllib
import json
import mp3play

def music():
text = entry.get()
text = text.encode('utf-8')
text = urllib.quote(text)
if not text:
tkMessageBox.showinfo('温馨提示', '您可以输入以下内容进行搜索\n1.歌曲名\n2.歌手名\n3.部分歌词')
return
html=urllib.urlopen('http://s.music.163.com/search/get/?type=1&s=%s&limit=9' %text).read()
text = json.loads(html)
list_s = text['result']['songs']
list_url = []
global list_url
list_name = []
global list_name
listbox.delete(0,listbox.size())
for i in list_s:
listbox.insert(END,i['name']+ "("+i['artists'][0]['name']+")")
list_url.append(i['audio'])
list_name.append(i['name'])

def play(event):
global mp3
sy = listbox.curselection()[0]
mp3 = mp3play.load(list_url[sy])
mp3.play()
urllib.urlretrieve(list_url[sy], list_name[sy] + '.mp3')

root = Tk()
root.title("Tkinter Music")
root.geometry('+300+100')
entry = Entry(root)
entry.pack()
button = Button(root,text='搜索歌曲',command=music)
button.pack()
listbox = Listbox(root,width=50)
listbox.bind('<Double-Button-1>',play)
listbox.pack()
mainloop()
标签:python,播放器
0
投稿

猜你喜欢

  • 给Python入门者的一些编程建议

    2023-09-24 03:22:13
  • golang 数组去重,利用map的实现

    2024-04-27 15:37:49
  • asp程序定义变量比不定义变量速度快一倍

    2012-12-04 20:06:32
  • SQL Server数据库连接中常见的错误分析

    2009-01-15 12:51:00
  • OpenCV实现图像平滑处理的方法汇总

    2023-07-12 14:44:33
  • 图片滤镜效果[IE Only]

    2009-06-14 19:49:00
  • CentOS 7 安装python3.7.1的方法及注意事项

    2023-03-10 21:23:53
  • mysql 常用命令集锦(Linux/Windows)

    2024-01-17 07:26:20
  • 双击编辑功能如何实现

    2008-02-26 16:17:00
  • SQL Server Reporting Services 匿名登录的问题及解决方案

    2024-01-20 04:24:05
  • Java操作MongoDB数据库方法详解

    2024-01-19 11:37:38
  • 完美解决phpstudy安装后mysql无法启动(无需删除原数据库,无需更改任何配置,无需更改端口)直接共存

    2023-11-14 17:39:47
  • Bootstrap编写一个兼容主流浏览器的受众门户式风格页面

    2024-05-02 17:32:01
  • 10分钟教你本地配置多个git ssh连接的方法

    2022-03-05 04:44:53
  • J2EE基础应用:J2EE中SQL语句自动构造方法

    2009-09-18 09:06:00
  • 微信小程序分享海报生成的实现方法

    2024-05-02 17:29:49
  • 利用python模拟实现POST请求提交图片的方法

    2021-02-20 05:58:21
  • Python实现K-means聚类算法并可视化生成动图步骤详解

    2021-06-20 23:10:40
  • JavaScript常用本地对象小结

    2024-06-18 09:23:44
  • Pandas 时间序列分析中的resample函数

    2023-12-06 16:38:33
  • asp之家 网络编程 m.aspxhome.com