zoukankan      html  css  js  c++  java
  • python 简易音乐盒子

    #!/usr/bin/env python
    #-*- coding:utf-8 -*-

    from Tkinter import *
    import tkMessageBox
    import urllib

    def music():
    if e1.get() == '':
    tkMessageBox.showinfo('提示:','请先输入歌曲名字再搜索')
    return
    name = e1.get().encode('utf-8')
    name = urllib.quote(name)
    html = urllib.urlopen('http://music.163.com/#/search/m/?id=347230&s=%s&type=1' %name).read()
    print html
    def play():
    pass
    top = Tk() #top就等同于窗口
    top.title('音乐搜索') #就是窗口顶部的标题
    top.geometry('500x300+600+300') #设置窗口的大小:长500,宽300,600为横坐标,300为纵坐标
    top.resizable(width=False,height=False) #设置窗口大小不能变大变小

    e1 = Entry(top) #e1 就是搜索框,Entry(top)就是让搜索框在top添加
    e1.pack() #让搜索框显示
    B = Button(top,text='搜索',command = music).pack()
    var = StringVar()
    Lb = Listbox(top,width=50,listvariable=var)
    Lb.bind('<Double-Button-1>',play)
    Lb.pack()
    top.mainloop()

    ###################可用版#########################

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

    list_url = []
    list_name = []
    def music():
      text = entry.get()
      text = text.encode('utf-8')
      text = urllib.quote(text)
      if text == '':
        tkMessageBox.showinfo('温馨提示','您可以输入以下内容进行搜索 1.歌曲名 2.歌手名 3.部分歌词')
        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("Rain 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()

  • 相关阅读:
    菜单项向子页面传递参数
    Grid中添加链接,打开选项卡页面
    FineUI与百度地图简单示例 (转帖)
    AppBox中main树节点单击事件JS(还有叶子的节点的页面链接)
    FineUI中在一个页面中通过控件事件(JS)向父页面中添加Tab页
    如何使用button在tab中新建打开一个链接页
    系统service
    官员详解官场对领导称谓讲究:叫大不叫小
    搞笑对话
    陆琪:男人生存的意义,就是赚钱养老婆
  • 原文地址:https://www.cnblogs.com/shanhua-fu/p/6940590.html
Copyright © 2011-2022 走看看