该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
submenu.add_command(label = "打开文件",command = self.add)
menu.add_cascade(label="文件",menu=submenu)
submenu = tkinter.Menu(menu,tearoff=0)
submenu.add_command(label = "播放",command = self.play)
submenu.add_command(label = "暂停",command = self.pause)
submenu.add_separator()
submenu.add_command(label = "停止",command = self.stop)
menu.add_cascade(label="控制",menu=submenu)
submenu = tkinter.Menu(menu,tearoff=0)
submenu.add_command(label = "首曲",command = self.previous)
submenu.add_command(label = "下一曲",command = self.next)
menu.add_cascade(label="曲目选择",menu=submenu)
def popupmenu(event):
menu.post(event.x_root,event.y_root)
root.bind("",popupmenu)
root.config(menu = menu)
self.wmp = Dispatch('WMPlayer.OCX')
def MainLoop(self):
self.root.title("Vicious Music Player")
self.root.minsize(590,380)
self.root.maxsize(590,380)
self.root.mainloop()
def add(self):
file = tkinter.filedialog.askopenfilenames(title = "Python Music Player",
filetypes = [("MP3","*.mp3"),("WMA","*.wma"),("WAV","*.wav")])
if file:
filelist = file.split(None)
for i in filelist:
media = self.wmp.newMedia(i)
self.wmp.currentPlayList.appendItem(media)
self.playList.insert(tkinter.END,i + "\n")
def play(self):
self.wmp.controls.play()
def pause(self):
self.wmp.controls.pause()
def next(self):
self.wmp.controls.next()
def stop(self):
self.wmp.controls.stop()
def previous(self):
self.wmp.controls.previous()
window = Window()
window.MainLoop()