欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python開發(fā)簡易版在線音樂播放器

 更新時間:2017年03月03日 13:52:54   作者:whaben  
這篇文章主要為大家詳細介紹了python開發(fā)簡易版在線音樂播放器的相關(guān)資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

在線音樂播放器,使用python的Tkinter庫做了一個界面,感覺這個庫使用起來還是挺方便的,音樂的數(shù)據(jù)來自網(wǎng)易云音樂的一個接口,通過urllib.urlopen模塊打開網(wǎng)址,使用Json模塊進行數(shù)據(jù)的解析,最后使用mp3play庫對音樂進行在線播放,也可以同時下載mp3,開發(fā)環(huán)境: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('溫馨提示', '您可以輸入以下內(nèi)容進行搜索\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()

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論