from tkinter import *
from tkinter.font import *
from tkinter import messagebox
from tkinter import filedialog
from pygame import * # https://fishc.com.cn/forum.php?mod=viewthread&tid=177465&highlight=mp3
root = Tk()
root.title('MP3 player')
root.resizable(0,0)
mixer.init() # 初始化播放器
def about():
tk0 = Tk()
tk0.attributes('-alpha', 0.9)
tk0.title('关于 MP3 player')
tk0.resizable(0,0)
tk0.mainloop()
def docs():
tk1 = Tk()
tk1.attributes('-alpha', 0.9)
tk1.title('帮助文档')
tk1.resizable(0,0)
l0b = Label(tk1, text='帮助文档', font=ft0)
l0b.grid(row=0, column=0, padx='5px', pady='2px')
tk1.mainloop()
# waiting to be write
def openfile():
global fn
fn = filedialog.askopenfilename()
fnf = fn.split('/')
fnff = fnf[-1]
l1.config(text=fnff[:fnff.rfind('.')], fg='black')
mixer.music.load(fn)
mixer.music.play()
mixer.music.pause()
b2.config(text=' ▷ ', fg='green', command=startplay)
mixer.music.set_volume(s1.get()*0.01)
def startplay():
mixer.music.unpause()
b2.config(text=' ‖ ', fg='blue', command=rest)
def rest():
mixer.music.pause()
b2.config(text=' ▷ ', fg='green', command=startplay)
def stopplay():
mixer.music.stop()
l1.config(text='还没有打开文件哟~', fg='gray')
def volumeconsole(self):
mixer.music.set_volume(s1.get()*0.01)
l5.config(text=str(s1.get()) + '%')
def playloops(self):
pass
def fpass():
pass
def bpass():
pass
ft0 = Font(family='微软雅黑', size=12)
ft1 = Font(size=15)
m0 = Menu(root)
m1 = Menu(m0, tearoff=False)
m1.add_command(label='关于 MP3 player', command=about)
m1.add_separator()
m1.add_command(label='帮助文档', command=docs)
m0.add_cascade(label='更多', menu=m1)
root.config(menu=m0)
l0 = Label(root, text='正在播放 :', fg='orange',font=ft0)
l0.grid(row=0, column=0, padx='5px', pady='2px')
l1 = Label(root, font=ft0)
l1.config(text='还没有打开文件哟~', fg='gray')
l1.grid(row=0, column=1, columnspan=2, padx='5px', pady='2px')
# l2 = Label(root, font=ft0)
# l2.config(text='00:00')
# l2.grid(row=1, column=0, padx='5px', pady='2px')
# s0 = Scale(root, from_=0, to=100, orient=HORIZONTAL, length=250, showvalue=0, command=playloops)
# s0.grid(row=1, column=1, columnspan=3)
# l3 = Label(root, font=ft0)
# l3.config(text='00:00')
# l3.grid(row=1, column=4, padx='5px', pady='2px')
b0 = Button(root, text=' ✉ ', command=openfile, fg='purple', font=ft0)
b0.grid(row=1, column=2, padx='5px', pady='2px')
# b1 = Button(root, text=' ◁◁ ', command=fpass, fg='grey', font=ft0)
# b1.grid(row=2, column=0, padx='5px', pady='2px')
b2 = Button(root, font=ft0)
b2.grid(row=1, column=0, padx='5px', pady='2px')
b2.config(text=' ▷ ', fg='green', command=startplay)
# b3 = Button(root, text=' ▷▷ ', command=bpass, fg='gray', font=ft0)
# b3.grid(row=2, column=2, padx='5px', pady='2px')
b4 = Button(root, text=' □ ', fg='red', command=stopplay, font=ft1)
b4.grid(row=1, column=1, padx='5px', pady='2px')
l4 = Label(root, fg='gray', font=ft0)
l4.config(text=' ♫ ')
l4.grid(row=3, column=0, padx='5px', pady='2px')
s1 = Scale(root, from_=0, to=100, orient=HORIZONTAL, length=200, showvalue=0, command=volumeconsole)
s1.grid(row=3, column=1)
l5 = Label(root, fg='#cc99ff', font=ft0)
l5.config(text=str(s1.get()) + '%')
l5.grid(row=3, column=2)
root.mainloop()