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