This example describes how Python opens and plays a WAV file using Wxpython. Share to everyone for your reference. The implementation method is as follows:
"' Wx_lib_filebrowsebutton_sound.pyselect a sound file and play Itwx.lib.filebrowsebutton.FileBrowseButton (parent, LabelText, Filemask) (combines WX. Textctrl and Wxfiledialog widgets) wx. Sound (fileName, isresource=false) tested with Python27 and wxPython291 by Vegaseat 25jul2013 ' 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.