python开发简易版在线音乐播放器
Python  /  管理员 发布于 7年前   321
在线音乐播放器,使用python的Tkinter库做了一个界面,感觉这个库使用起来还是挺方便的,音乐的数据来自网易云音乐的一个接口,通过urllib.urlopen模块打开网址,使用Json模块进行数据的解析,最后使用mp3play库对音乐进行在线播放,也可以同时下载mp3,开发环境:python2.7,附上源代码如下:
# _*_ coding:utf-8 _*_from Tkinter import *import tkMessageBoximport urllibimport jsonimport 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()以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
test1 在
opencode + Oh-my-openagent,我的第一个免费的ai编程智能体管家:Sisyphus中评论 test..122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..Zita 在
Google AI Studio升级全栈 vibe coding体验,可直接构建带登录和数据库的应用中评论 111222..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号
