• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python使用wxPython打开并播放wav文件的方法

python使用wxPython打开并播放wav文件的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了wxpython python3,python wxpython,python安装wxpython,wxpython python3.5,wxpython python2.7等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了python使用wxPython打开并播放wav文件的方法。分享给大家供大家参考。具体实现方法如下:

''' wx_lib_filebrowsebutton_sound.py
select a sound file and play it
wx.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 wx
import wx.lib.filebrowsebutton

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(panel,
      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, 10)
    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 = 600
height = 90
MyFrame(None, mytitle, (width, height)).Show()
app.MainLoop()
</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • 在Ubuntu系统下安装使用Python的GUI工具wxPython
  • 在Ubuntu系统下安装使用Python的GUI工具wxPython
  • wxPython定时器wx.Timer简单应用实例
  • python使用wxpython开发简单记事本的方法
  • python使用wxPython打开并播放wav文件的方法
  • python使用wxPython打开并播放wav文件的方法
  • 用Python中的wxPython实现最基本的浏览器功能
  • 分析Python编程时利用wxPython来支持多线程的方法
  • python通过wxPython打开一个音频文件并播放的方法
  • Python中使用wxPython开发的一个简易笔记本程序实例

相关文章

  • Python使用Socket(Https)Post登录百度的实现代码
  • python基于pyDes库实现des加密的方法
  • Python2.7简单连接与操作MySQL的方法
  • 在Linux上安装Python的Flask框架和创建第一个app实例的教程
  • python处理xml文件的方法小结
  • python使用wxPython打开并播放wav文件的方法
  • 使用Python中的线程进行网络编程的入门教程
  • python进阶_浅谈面向对象进阶
  • 在Python中操作字符串之startswith()方法的使用
  • 举例讲解Python中的list列表数据结构用法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 批处理与python代码混合编程的方法
    • python和bash统计CPU利用率的方法
    • Django中模版的子目录与include标签的使用方法
    • Python中的测试模块unittest和doctest的使用教程
    • python创建线程示例
    • 详解Django框架中用户的登录和退出的实现
    • 在Python操作时间和日期之asctime()方法的使用
    • python实现域名系统(DNS)正向查询的方法
    • 简单掌握Python的Collections模块中counter结构的用法
    • Python生成随机数组的方法小结

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有