Online music player, using the Python Tkinter Library made an interface, feel that the library is very convenient to use, music data from the NetEase cloud music an interface, Open the URL through the Urllib.urlopen module, use the JSON module for data parsing, and finally use the Mp3play library to play online music, you can also download MP3, development environment: python2.7, with the source code as follows:
# _*_ Coding:utf-8 _*_from Tkinter import *import tkmessageboximport urllibimport jsonimport mp3play def Music (): Text = E Ntry.get () Text = Text.encode (' utf-8 ') Text = urllib.quote (text) if not text:tkMessageBox.showinfo (' warm tip ', ' You can enter the following content to search Cable \n1. Song name \n2. Singer name \n3. Part lyrics ') 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.curselec tion () [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= ' Search songs ', Command=music) button.pack () ListBox = ListBox (ROOT,WIDTH=50) listbox.bind (' <Double-Button-1> ', play) Listbox.pack () Mainloop ()
The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support topic.alibabacloud.com.