How Python uses Wxpython to open and play WAV files _python

Source: Internet
Author: User
Tags error handling

This article 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.py Select a sound file and play it Wx.lib.filebrowsebutton.FileBrowseButton (parent, LA Beltext, Filemask) (combines WX. Textctrl and Wxfiledialog widgets) wx. Sound (FileName, isresource=false) tested with Python27 and wxPython291 by Vegaseat 25jul2013 ' ' Import wx import Wx.lib.f Ilebrowsebutton class 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. Panel (self) # mask file browser to look for. wav sound files self.fbb = Wx.lib.filebrowsebutton.FileBrowseButton (P Anel, 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, 0Wx. align_center_vertical) # Create a border space border = wx. Boxsizer (WX. VERTICAL) border. ADD (Hsizer, 0, WX. Expand|wx. All) 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 frame mytitle = "Wx.lib.filebrowsebutton and WX." Sound "width = height = myframe (None, MyTitle, (width, height))." Show () app. Mainloop ()

I hope this article will help you with your Python programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.