我正在製作音樂播放器。我有一個列表框,其中包含目錄「歌曲」中的歌曲列表。如何確定選擇了哪首歌曲,以及如何繼續播放?如何確定在wxpython中選擇了哪個列表框項目
CODE:
songlist = os.listdir('songs')
self.myListBox = listbox = wx.ListBox(panel2, -1, (10,200), (140,200), songlist, wx.LB_SINGLE)
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.selLoadFile, listbox)
def selLoadFile(self, event):
file_path = os.path.join(os.os.getcwd(), "songs", self.myListBox.getSelectedItem())
self.doLoadFile(file_path)
########### I believe the problem is above^here. But I could be wrong.
def Load(self, event):
dlg = wx.FileDialog(self, "Choose a media file", "songs", "", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
self.doLoadFile(path)
dlg.Destroy()
def doLoadFile(self, path):
if not self.mc.Load(path):
wx.MessageBox("Unable to load %s: Unsupported format?" % path, "ERROR", wx.ICON_ERROR | wx.OK)
else:
folder, filename = os.path.split(path)
self.st_file.SetLabel('%s' % filename)
self.mc.SetBestFittingSize()
self.mc.Play()
感謝您的信息!這是一個很好的教程和例子,這是我用來幫助建立我的音樂播放器的第一個地方。哦,我正在使用wx.media.MediaCtrl – Worm 2012-07-19 15:43:26