• 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中使用bidict模块双向字典结构的奇技淫巧
  • Python实现栈的方法
  • Python正则表达式匹配HTML页面编码
  • python里对list中的整数求平均并排序
  • python实现清屏的方法
  • Python中基本的日期时间处理的学习教程
  • Python循环语句之break与continue的用法
  • Python中的__SLOTS__属性使用示例
  • python中enumerate的用法实例解析
  • Python使用py2exe打包程序介绍

文章分类

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

最近更新的内容

    • python3中int(整型)的使用教程
    • Python高效编程技巧
    • Python对两个有序列表进行合并和排序的例子
    • Python中list初始化方法示例
    • python求解水仙花数的方法
    • 使用python检测主机存活端口及检查存活主机
    • Python psutil模块简单使用实例
    • Python代理抓取并验证使用多线程实现
    • python重试装饰器示例
    • python模块restful使用方法实例

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

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