切歌以及列表功能完成版本 界面如下:代码如下:import osimport pygamefrom tkinter import *from tkinter.filedialog import askdirectorydef mouseCallBack(*args):indexs = listb.curselection()index = int(...

切歌以及列表功能完成版本 界面如下:
代码如下:
import os
import pygame
from tkinter import *
from tkinter.filedialog import askdirectory
def mouseCallBack(*args):
indexs = listb.curselection()
index = int(indexs[0])
#str_value = str(index)#数字转字符串
print(" mouse click "+path_+"/"+listSongs[index])
curPath = path_+"/"+listSongs[index]
try:
pygame.mixer.music.stop()
except:
print("stop play error")
pygame.mixer.init()
track = pygame.mixer.music.load(curPath)
pygame.mixer.music.play()
def getMp3List(folder):
global list
global listSongs
list = os.listdir(folder)
listSongs = []
counter = 0
#为第一个Listbox设置绑定事件
listb.bind("<<ListboxSelect>>",mouseCallBack)
while counter < len(list):
if os.path.splitext(list[counter])[1]==".mp3":
print(list[counter])
listSongs.append(list[counter])
listb.insert(END,list[counter])
counter +=1
listb.pack()
def selectFile():
global path_
path_ = askdirectory()
path.set(path_)
# print("path "+path)
print("path_ "+path_)
getMp3List(path_)
def about():
label = Label(root, text='花景音乐电脑版\n ', fg='red', bg='white')
label.pack(expand=YES, fill=BOTH)
root = Tk()
path = StringVar()
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label='打开', command=selectFile)
filemenu.add_command(label='保存')
filemenu.add_separator()
filemenu.add_command(label='退出', command=root.quit)
menubar.add_cascade(label='文件', menu=filemenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label='关于作者', command=about)
menubar.add_cascade(label='关于', menu=helpmenu)
listb = Listbox(root,width=500,height=300)
root.config(menu=menubar)
root.geometry('800x500')
root.mainloop()
织梦狗教程
本文标题为:Python学习之windows音乐播放器之路(二)


基础教程推荐
猜你喜欢
- MySQL数据优化-多层索引 2023-08-11
- Python+OpenCV实战之实现文档扫描 2022-10-20
- 远程和Ubuntu服务器进行Socket通信,使用python和C#(准备篇) 2023-09-05
- 云服务器Ubuntu更改默认python版本 2023-09-03
- 创建python虚拟环境(在ubuntu16.04中) 2023-09-04
- 使用Pycharm创建一个Django项目的超详细图文教程 2022-09-02
- linux 安装 python3 2023-09-03
- python验证多组数据之间有无显著差异 2023-08-08
- windows下面使用多版本Python安装指定版本的虚拟环境 2023-09-04
- Python爬虫爬取属于自己的地铁线路图 2023-08-05