This example describes how Python opens an audio file and plays it through Wxpython. Share to everyone for your reference. Specific as follows:
This snippet uses the Wx.lib.filebrowsebutton.FileBrowseButton control to open a WAV file, using Wx.sound to play
Import Wximport wx.lib.filebrowsebuttonclass myframe (WX. Frame): Def __init__ (self, parent, MyTitle, mysize): WX. Frame.__init__ (self, parent, Wx.id_any, MyTitle, size=mysize) self. Setbackgroundcolour ("green") panel = WX. The Panel (self) # mask file browser. wav sound files self.fbb = Wx.lib.filebrowsebutton.FileBrowseButton (pan El, labeltext= "Select a WAVE file:", filemask= "*.wav") Self.play_button = wx. button (panel, Wx.id_any, ">> Play") Self.play_button. Bind (WX. Evt_button, Self.onplay) # setup the layout with sizers Hsizer = wx. Boxsizer (WX. Horizontal) Hsizer. ADD (SELF.FBB, 1, WX. align_center_vertical) Hsizer. ADD (Self.play_button, 0, WX. align_center_vertical) # Create a border space border = wx. Boxsizer (WX. VERTICAL) border. ADD (Hsizer, 0, WX. Expand|wx. All, ten) panel. Setsizer (Border) def onplay (self, evt): filename = self.fbb.GetValue () Self.sound = WX. Sound (filename) # error handling ... if Self.sound.IsOk (): Self.sound.Play (WX. Sound_async) else:wx. MessageBox ("Missing or invalid sound file", "Error") app = WX. APP (0) # Create a MyFrame instance and show the Framemytitle = "Wx.lib.filebrowsebutton and WX. Sound "width = 600height = 90MyFrame (None, MyTitle, (width, height)). Show () app. Mainloop ()
Hopefully this article will help you with Python programming.