我犯了一個音樂播放器,播放列表,但因爲只有首歌的名字在播放列表不是一個完整的MP3文件將在播放列表中的歌曲無法播放。你能告訴我如何處理這個問題嗎? 這裏是我的代碼:音樂播放器的播放列表
from Tkinter import *
import mp3play
import tkFileDialog
import Tkinter
import tkFont
import Tkinter as tk
#from PIL import ImageTk,Image
def open_file(): #Opens a dialog box to open .mp3 file
global music #then sends filename to file_name_label.
global mp3
global play_list
filename.set (tkFileDialog.askopenfilename(defaultextension = ".mp3", filetypes=[("All Types", ".*"), ("MP3", ".mp3")]))
playlist = filename.get()
playlist_pieces = playlist.split("/")
play_list.set (playlist_pieces[-1])
playl = play_list.get()
play_list_display.insert(END, playl)
mp3 = filename.get()
print mp3
music = mp3play.load(mp3)
pieces = mp3.split("/")
name.set (pieces[-1])
def play(): #Plays the .mp3 file
music.play()
def stop(): #Stops the .mp3 file
music.stop()
def pause(): #Pauses or unpauses the .mp3 file
if music.ispaused() == True:
music.unpause()
elif music.ispaused() == False:
music.pause()
def vol(event): #Allows volume to be changed with the slider
v = Scale.get(volume_slider)
music.volume(v)
def tune_changed(event):
idx = event.widget.curselection()[0]
print ("Now playing %s" % event.widget.get(idx))
def Exit():
exit()
root = tk.Tk()
root.title("EmoPlayer")
root.configure(background='black')
#root = Tk()
root.geometry('300x100+750+300')
filename = Tkinter.StringVar()
name = Tkinter.StringVar()
play_list = Tkinter.StringVar()
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0, bg="black", fg="Orange")
menubar.add_cascade(label='File', menu = filemenu)
filemenu.add_command(label='Open', command = open_file)
filemenu.add_separator()
filemenu.add_command(label='Exit', command = Exit)
root.config(menu=menubar)
open_file = Button(root, width = 6, height = 1, text = 'Mood',fg='Orange', bg='black')
open_file.grid(row=0, column=3)
play_button = Button(root, width = 5, height = 1, text='Play', fg='Orange', command = play, bg="black")
play_button.grid(row=0, column=0, sticky = W)
stop_button = Button(root, width = 5, height = 1, text='Stop',fg='Orange', command = stop, bg="black")
stop_button.grid(row=0, column=1, sticky = W)
pause_button = Button(root, width = 5, height = 1, text='Pause',fg='Orange', command = pause, bg="black")
pause_button.grid(row=0, column=2)
volume_slider = Scale(root, label='Volume', orient = 'horizontal', fg = 'Orange', command = vol, bg="black")
volume_slider.grid(row=0, column=4)
file_name_label = Label(root, font=('Comic Sans', 8), fg = 'Orange', wraplength = 300, textvariable=name, bg="black")
file_name_label.grid(row=3, column=0, columnspan=8)
play_list_window = Toplevel(root, height = 150, width = 100)
play_list_window.title("Playlist")
play_list_display = Listbox(play_list_window, selectmode=EXTENDED, width = 50, bg="Dark Slate grey", fg="Orange")
play_list_display.bind("<Double-Button-1>", tune_changed)
play_list_display.pack()
play_list_window.mainloop()
root.mainloop()
感謝ü這麼多..它幫助 我要問,什麼是「自我」的目的。爲什麼你在每一行中都使用它? 和是否有可能將這些MP3文件路徑,這是在播放列表中,在數組?? ??以及如何做到這一點? – frivolous
我也做過保存播放列表。這個播放器播放幾乎所有的歌曲,但播放幾首歌曲時,它給了我這個錯誤:ValueError:對於基數爲10的int()無效文字:'指定的設備未打開或未被MCI識別。 ...現在我無法理解這個錯誤。 – frivolous