pygame 的 音乐播放
本帖最后由 weiter 于 2020-11-17 22:12 编辑为什么会报错呀?
在 play 那里少的参数是个啥……
百度没找到……
要怎么解决呀?
在线求大佬!
挺急的……
from tkinter import *
from tkinter.font import *
from tkinter import messagebox
from tkinter import filedialog
from threading import * # learning to use
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)
def about():
tk0 = Tk()
tk0.attributes('-alpha', 0.7)
tk0.title('about MP3 player')
tk0.resizable(0,0)
l0a = Label(tk0, text='made by weiter who is not good at programming', fg='blue', font=ft)
l0a.grid(row=0, column=0, columnspan=2, padx='5px', pady='2px')
l1a = Label(tk0, text='e-mail', font =ft)
l1a.grid(row=1, column=0, padx='5px', pady='2px')
l2a = Label(tk0, text='739095262@qq.com', fg='#AAAAAA', font=ft)
l2a.grid(row=1, column=1, padx='5px', pady='2px')
tk0.mainloop()
def docs():
tk1 = Tk()
tk1.attributes('-alpha', 0.7)
tk1.title('help docs')
tk1.resizable(0,0)
l0b = Label(tk1, text='help docs', font=ft)
l0b.grid(row=0, column=0, padx='5px', pady='2px')
tk1.mainloop()
# waiting to be write
def openfile():
global fn
m0 = messagebox.askokcancel('MP3 player', 'are you shure?')
fn = filedialog.askopenfilename()
fnf = fn.split('/')
l2 = Label(root, text=fnf[-1], font=ft)
l2.grid(row=0, column=1, columnspan=2, padx='5px', pady='2px')
mixer.init()
def startplay():
mixer.music.load(fn) # bug
mixer.music.play(fn) # bug
def rest():
pass
def stopplay():
pass
def voiceconsole():
pass
ft = Font(family='微软雅黑', size=12)
m0 = Menu(root)
m1 = Menu(m0, tearoff=False)
m1.add_command(label='about', command=about)
m1.add_separator()
m1.add_command(label='docs', command=docs)
m0.add_cascade(label='help', menu=m1)
root.config(menu=m0)
l1 = Label(root, text='load :', fg='orange',font=ft)
l1.grid(row=0, column=0, padx='5px', pady='2px')
l2 = Label(root, font=ft) # text='name', name in openfile
l2.config(text='none')
l2.grid(row=0, column=1, columnspan=2, padx='5px', pady='2px')
b1 = Button(root, text='open', command=openfile, fg='purple', font=ft)
b1.grid(row=0, column=3, padx='5px', pady='2px')
b2 = Button(root, text=' ▷ ', command=startplay, fg='green', font=ft)
b2.grid(row=1, column=0, padx='5px', pady='2px')
b3 = Button(root, text=' ‖ ', command=rest, fg='blue', font=ft)
b3.grid(row=1, column=1, padx='5px', pady='2px')
b4 = Button(root, text=' □ ', command=stopplay, fg='red', font=ft)
b4.grid(row=1, column=2, padx='5px', pady='2px')
b5 = Button(root, text=' ♫ ', command=voiceconsole, fg='gray', font=ft)
b5.grid(row=1, column=3, padx='5px', pady='2px')
root.mainloop()
发下完整点的代码
Twilight6 发表于 2020-11-17 22:06
发下完整点的代码
有点长啊……我刚刚发了个有关的部分,主要是代码才刚刚起步非常不完整……(我发主贴里面) weiter 发表于 2020-11-17 22:10
有点长啊……我刚刚发了个有关的部分,主要是代码才刚刚起步非常不完整……(我发主贴里面)
百度到的,改成这样,第二个 方法 不用传入文件名
def startplay():
mixer.music.load(fn) # bug
mixer.music.play() # bug
Twilight6 发表于 2020-11-17 22:18
百度到的,改成这样,第二个 play 不用传入文件名
好的,我先试一下,谢谢 Twilight6 发表于 2020-11-17 22:18
百度到的,改成这样,第二个 方法 不用传入文件名
感谢大佬!
同样都是百度为何区别如此之大……{:10_266:} weiter 发表于 2020-11-17 22:19
感谢大佬!
同样都是百度为何区别如此之大……
{:5_91:}
页:
[1]