Python: How do I code to make a button do something else if pressed a second time?
<p>I have this music program, so when I click a button it starts playing music. When I press it again, I want it to stop the music, but instead it plays the same beat on top of the first one. How do I get around doing this?</p>

<p>EDIT: Oops, silly me, forgot about the details. I use Python 2.7, wxFormBuilder, and Easy Eclipse. Here's the code:</p>

<pre><code>import gui
import wx
import wx.media
import pygame
import tkFileDialog

class MainFrame( gui.GUI_MainFrame):
    def __init__( self, parent ): #Definerar KunddatabasMainFrame
        pygame.init()
        gui.GUI_MainFrame.__init__( self, parent ) #Initierar MainFrame f�nstret
        self.sound1=pygame.mixer.Sound('beat1.wav')
        self.sound2=pygame.mixer.Sound('beat2.wav')
        self.recording = False

    def evtBrowse1(self, evt):
        tkFileDialog.askopenfilename()

    def evtSoOne(self, evt):
        self.sound1.play(loops=-1)
</code></pre>
