Python to develop a simple version of the online music player sample code

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.