在wxpython类中不能停止音乐

在wxpython类,可以导入并播放音乐,不能停止音乐,期待你的解答,谢谢!

import wx
import pygame
class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(None,title='music',size=(500,300),pos=(50,50))
        panel=wx.Panel(parent=self)
        self.b1=wx.Button(parent=panel,label='start',id=1,pos=(150,100))
        self.b2=wx.Button(parent=panel,label='stop',id=2,pos=(250,100))
        self.Bind(wx.EVT_BUTTON,self.on_click,id=1,id2=5)

    def music(self):
        filepath='1.mp3'
        pygame.mixer.init()
        pygame.mixer.music.load(filepath)
        pygame.mixer.music.play(start=0.0)
        
    def on_click(self,event):
        event_id=event.GetId()
        if event_id==1:
            self.music()
        elif event_id==2:
            pygame.mixer.pause()

if __name__=="__main__":
    app=wx.App()
    frm=MyFrame()
    frm.Show()
    app.MainLoop()
    

参考这样用计数的方式让它停止:

import wx
import pygame
import os
import random
import time
class IsPrimeFrame(wx.Frame):
    def __init__(self,superion,count=0):
        wx.Frame.__init__(self,parent=superion ,title='Big Eye',size = (400,200))
        self.count=count
        panel = wx.Panel(self)
        panel.SetBackgroundColour('Red')
        self.buttonPlay = wx.Button(parent=panel,label='PLAY',pos=(50,90))
        self.Bind(wx.EVT_BUTTON,self.OnbuttonPlay,self.buttonPlay)

        self.buttonPause = wx.Button(parent=panel,label='Pause',pos=(150,90))
        self.Bind(wx.EVT_BUTTON,self.OnbuttonPause,self.buttonPause)

        self.buttonQuit = wx.Button(parent=panel,label='Quit',pos=(250,90))
        self.Bind(wx.EVT_BUTTON,self.OnbuttonQuit,self.buttonQuit)
    def OnbuttonPlay(self,even):
        folder = r'd:\music'
        musics = [folder+'\\'+music for music in os.listdir(folder) if music.endswith('.mp3')]
        pygame.mixer.init()
        total =len(musics)
        if not pygame.mixer.music.get_busy():
            playMusic = random.choice(musics)
            pygame.mixer.music.load(playMusic)
            pygame.mixer.music.play(1)
            print 'playing...',playMusic
        else:
            time.sleep(1)
    def OnbuttonPause(self,even):
        if self.count%2 ==0:
            pygame.mixer.music.pause()
        else:
            pygame.mixer.music.unpause()
        self.count = self.count+1
    def OnbuttonQuit(self,even):
        dlg = wx.MessageDialog(self,'Really Quit?','Caution',wx.CANCEL|wx.OK|wx.ICON_QUESTION)
        if dlg.ShowModal() ==wx.ID_OK:
            self.Destroy()
if __name__ == '__main__':
    aa = wx.App()
    frame = IsPrimeFrame(None)
    frame.Show()
    aa.MainLoop()