Python 2.7, pygame, combing pause and unpause button.
Question: I am coding a simple music player.

I have searched the other questions in Stackoverflow, however, the solutions
do not work with my pygame build.

My code is below. I am using Tkinter for the gui build.

    
    
    import sys
    from Tkinter import *
    import tkMessageBox
    import pygame
    
    myGui = Tk()
    
    
    def mClose():
        mExit = tkMessageBox.askokcancel(title="Quit", message="are you sure?")
        if mExit ==True:
            myGui.destroy()
            return
    
    def mPlay():    
        pygame.mixer.init()
        pygame.mixer.music.load("/home/david/Downloads/test.mp3")
        pygame.mixer.music.play()
    
    
    def unPause():
        pygame.mixer.music.unpause()        
    
    
    def mPause():
        pygame.mixer.music.pause()
    
    
    
    myGui.title("My Audio")
    myGui.geometry("200x200+600+300")
    mLabel = Label(myGui, text="My Audio").pack()
    
    
    ''' Button for Closing App'''
    mButton = Button(myGui, text="Close", command = mClose).pack()
    
    '''Play Button'''
    mButton = Button(myGui, text="Play", command = mPlay).pack()
    
    '''Pause Button'''
    mButton = Button(myGui, text="Pause", command = mPause).pack()
    
    '''UnPause Button'''
    mButton = Button(myGui, text="UnPause", command = unPause).pack() 
    

I have tired to combine pause and unpause by using
pygame.mixer.music.get_busy(). However, if it is paused the boolean still
returns true for being active.

I have used the following to no avail:

    
    
    def play_pause():
        paused = not paused
        if paused: pygame.mixer.music.unpause()
        else: pygame.mixer.music.pause()
    

I get the following:

    
    
    File "/home/david/Documents/tkinter_testing.py", line 29, in play_pause
        paused = not paused
    UnboundLocalError: local variable 'paused' referenced before assignment. 
    

Any ideas or help. Thanks in advance for any help.


Answer: You are assigning `paused` a value but calling itself for the value. I believe
what you're looking for is

    
    
    paused = False
    

or

    
    
    paused = not True
    

