【问题标题】:Custom sound in a message dialog box in wxPythonwxPython中消息对话框中的自定义声音
【发布时间】:2012-08-05 15:24:39
【问题描述】:

我想知道有什么方法可以在消息对话框出现后立即播放自定义声音?我唯一的限制是我只能为此使用 wxPython,为了参数,让我们调用声音文件'music.wav' 这是我到目前为止的代码(忽略有关播放文本的内容,那是我为它创建一个虚拟 GUI加载):

import wx
import time
import winsound, sys

class ButtonTest(wx.Frame):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,None,id,'Button/Text test frame',size=(800,500))
        panel=wx.Panel(self)

        button=wx.Button(panel, label='Exit', pos=(200,50), size=(-1,-1))
        self.Bind(wx.EVT_BUTTON, self.closer, button)
        self.Bind(wx.EVT_CLOSE, self.wincloser)




        ape=wx.StaticText(panel, -1, 'This text is STATIC', (200,80))
        ape.SetFont(wx.Font(25, wx.SWISS, wx.ITALIC, wx.BOLD, True,'Times New Roman'))

        def beep(sound):
            winsound.PlaySound('%s.wav'%sound, winsound.SND_FILENAME)



        #wx.FutureCall(1000, beep('C:\Users\Chris\Desktop\music'))
        box=wx.MessageDialog(None,'Is this a good test?','Query:',wx.ICON_ERROR)

        answer=box.ShowModal()
        box.Destroy
        beep('C:\Users\Chris\Desktop\music')


    def closer(self,event):
        self.Close(True)

    def wincloser(self,event):
        self.Destroy()

if __name__=='__main__':

    app=wx.PySimpleApp()
    frame=ButtonTest(None,id=-1)
    frame.Show()
    app.MainLoop()

【问题讨论】:

    标签: dialog wxpython message


    【解决方案1】:

    对于 Windows,有内置于 Python 的 winsound。否则,您将需要一个外部库,如 pyAudio 或 Snack Sound。另见Play a Sound with Python

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多