有界面的python音乐播放器(可下载音乐) 您所在的位置:网站首页 pygame播放音乐列表 有界面的python音乐播放器(可下载音乐)

有界面的python音乐播放器(可下载音乐)

2024-07-06 19:55| 来源: 网络整理| 查看: 265

tkinter+pygame+spider实现音乐播放器 1.确定页面

SongSheet ------ 显示歌单 MusicCtrl ------显示音乐一些控件(播放,跳转,音量调节) SearchWindows ------搜索栏(搜索歌曲默认显示20条,可下载)

songSheet.py

#!/usr/bin/env python # -*- coding:utf-8 -*- # @Author: Minions # @Date: 2019-11-24 19:51:16 # @Last Modified by: Minions # @Last Modified time: 2019-12-17 10:01:53 import tkinter import os from tkinter import ttk import time class SongSheet(tkinter.Frame): def __init__(self, master): self.frame = tkinter.Frame(master, height=230, width=300, bd=1, bg="SkyBlue") self.frame.place(x=0, y=0) self.filePath = "C:\Musics" self.music = "" # 点击歌曲获得更新的路径 self.count = 0 # 计数,共多少歌曲 def run(self): # 搜索按钮 searchBtn = tkinter.Button(self.frame, text="更新", bg="SkyBlue", command=self.showSheet, width=10, height=1) searchBtn.place(x=0, y=200) # 显示歌单 def showSheet(self): self.count = 0 musics = os.listdir(self.filePath) tree = ttk.Treeview(self.frame) # 定义列 tree["columns"] = ("song") # 设置列,列还不显示 tree.column("song", width=95) # 设置表头 和上面一一对应 tree.heading("song", text="song") # 添加数据 往第0行添加 for music in musics: # 去除空格 music = "".join(music.split(" ")) tree.insert("", 0, text=self.count, values=(music)) self.count += 1 # 鼠标选中一行回调 def selectTree(event): for item in tree.selection(): item_text = tree.item(item, "values") self.music = "".join(item_text) # print(self.music) # 选中行 tree.bind('', selectTree) tree.place(width=300, height=200, x=0, y=0) # 添加滚动条 sy = tkinter.Scrollbar(tree) sy.pack(side=tkinter.RIGHT, fill=tkinter.Y) sy.config(command=tree.yview) tree.config(yscrollcommand=sy.set)

在这里插入图片描述

2.写出音乐控件

musicCtrl.py

#!/usr/bin/env python # -*- coding:utf-8 -*- # @Author: Minions # @Date: 2019-11-24 16:28:18 # @Last Modified by: Minions # @Last Modified time: 2019-12-17 10:25:31 import tkinter from tkinter import ttk import os import time import pygame from mutagen.mp3 import MP3 import random from songSheet import SongSheet class MusicCtrl(object): def __init__(self, master): self.frame = tkinter.Frame(master,height=150, width=700, bd=1, bg="MediumSeaGreen") self.frame.place(height=150, width=700, x=0, y=250) self.nowPaly = True # 是否正在播放音乐 self.filePath = r"C:\Musics" # 从该文件夹读取 self.musicPath = "" # 用于拼接音乐的路径 self.songSheet = SongSheet(master) self.songSheet.run() self.music = os.path.join(self.filePath,self.musicPath) # 音乐的路径 # 整合功能 def run(self): self.playMusic() self.refreshName() self.pauseMusic() self.volume() try: self.songPos() except: print("暂无歌曲载入!") # 播放音乐按钮 def playMusic(self): playBtn = tkinter.Button(self.frame, text="播放", command=self.playFunc, width=10,height=2) playBtn.place(x=300,y=10) # 实现播放功能 def playFunc(self): pygame.mixer.init() track = pygame.mixer.music.load(self.music)


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有