python实现音乐播放器播放列表_音乐播放器播放列表

fromTkinterimport*importmp3playimporttkFileDialogimportTkinterimporttkFontimportTkinterastkclassmusicplay:def__init__(self):self.music=Noneself.play_list=[]self.trackLocations=[]self.root=tk.Tk()self.root.title("EmoPlayer")self.root.configure(background='black')self.root.geometry('300x100+750+300')self.filename=Tkinter.StringVar()self.name=Tkinter.StringVar()self.play_list=Tkinter.StringVar()menubar=Menu(self.root)filemenu=Menu(menubar,tearoff=0,bg="black",fg="Orange")menubar.add_cascade(label='File',menu=filemenu)filemenu.add_command(label='Open',command=self.open_file)filemenu.add_separator()filemenu.add_command(label='Exit',command=self.Exit)self.root.config(menu=menubar)open_file=Button(self.root,width=6,height=1,text='Mood',fg='Orange',bg='black')open_file.grid(row=0,column=3)play_button=Button(self.root,width=5,height=1,text='Play',fg='Orange',command=self.play,bg="black")play_button.grid(row=0,column=0,sticky=W)stop_button=Button(self.root,width=5,height=1,text='Stop',fg='Orange',command=self.stop,bg="black")stop_button.grid(row=0,column=1,sticky=W)pause_button=Button(self.root,width=5,height=1,text='Pause',fg='Orange',command=self.pause,bg="black")pause_button.grid(row=0,column=2)self.volume_slider=Scale(self.root,label='Volume',orient='horizontal',fg='Orange',command=self.vol,bg="black")self.volume_slider.grid(row=0,column=4)file_name_label=Label(self.root,font=('Comic Sans',8),fg='Orange',wraplength=300,textvariable=self.name,bg="black")file_name_label.grid(row=3,column=0,columnspan=8)play_list_window=Toplevel(self.root,height=150,width=100)play_list_window.title("Playlist")self.play_list_display=Listbox(play_list_window,selectmode=EXTENDED,width=50,bg="Dark Slate grey",fg="Orange")self.play_list_display.bind("",self.tune_changed)self.play_list_display.pack()play_list_window.mainloop()self.root.mainloop()defopen_file(self):"""

Opens a dialog box to open .mp3 filemusic,

then sends filename to file_name_label.

"""self.filename.set(tkFileDialog.askopenfilename(defaultextension=".mp3",filetypes=[("All Types",".*"),("MP3",".mp3")]))self.playlist=self.filename.get()playlist_pieces=self.playlist.split("/")self.play_list.set(playlist_pieces[-1])playl=self.play_list.get()self.play_list_display.insert(END,playl)printself.filename.get()self.music=mp3play.load(self.filename.get())pieces=self.filename.get().split("/")self.trackLocations+=[self.filename.get()]self.name.set(pieces[-1])defplay(self):"""Plays the .mp3 file"""self.music.play()defstop(self):"""Stops the .mp3 file"""self.music.stop()defpause(self):"""Pauses or unpauses the .mp3 file"""ifself.music.ispaused():self.music.unpause()else:self.music.pause()defvol(self,event):"""Allows volume to be changed with the slider"""v=Scale.get(self.volume_slider)try:self.music.volume(v)except:passdeftune_changed(self,event):idx=event.widget.curselection()[0]self.music=mp3play.load(self.trackLocations[int(idx)])print("Now playing %s"%event.widget.get(idx))defExit(self):exit()if__name__=="__main__":musicplay()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值