wxpython中的声音和帧

时间:2019-10-27 07:02:38

标签: audio wxpython frame

下面的代码在播放音乐的过程中(大约15秒)显示“主框架”窗口,然后关闭,并显示另一个名为Info_frame的窗口。该代码正常工作。我的问题是:有没有办法改善我的代码并使之更有效?就像我如何在播放音乐时关闭“主框架”窗口,或者有没有可以代替wx.CallLater()的函数使用

class OtherFrame(wx.Frame):    

    def __init__(self, title, parent=None):

        wx.Frame.__init__(self, parent=parent, title=title,size=(452,600))

        self.Centre()

        self.Show()

class Welcome(wx.Frame):

    def __init__(self, parent, title):

        wx.Frame.__init__(self, None, title='Main Frame', size=(452,600))

        self.InitUI()

        self.Centre()

    def InitUI(self):

        icon = wx.Icon()

        icon.CopyFromBitmap(wx.Bitmap("sun.png", wx.BITMAP_TYPE_ANY))

        self.SetIcon(icon)

        png = wx.Image("Image_Welcome.jpg", wx.BITMAP_TYPE_ANY).Scale(452,600,quality=wx.IMAGE_QUALITY_NORMAL).ConvertToBitmap()

        wx.StaticBitmap(self, -1, png, (0, 0), (png.GetWidth(), png.GetHeight()))

        self.Show()

        self.playW()

    def playW(self):

        filename = 'sunrise.wav'

        winsound.PlaySound(filename, winsound.SND_ASYNC)

        wx.CallLater(17000, self.newFrame)


   def newFrame(self):

        self.Close() 

        frame = OtherFrame(title="Info_frame")



if __name__ == '__main__':
    app = wx.App()
    ex = Welcome(None,title="Main Frame")
    ex.Show()
    app.MainLoop()

0 个答案:

没有答案