在wxPython的消息对话框中自定义声音

时间:2012-08-08 13:43:19

标签: dialog wxpython message

我想知道有没有办法在消息对话框出现后立即播放自定义声音?我唯一的限制是我只能使用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()

1 个答案:

答案 0 :(得分:0)

对于Windows,有winound,它内置于Python中。否则,您将需要一个外部库,如pyAudio或Snack Sound。另请参阅Play a Sound with Python