In Python edit Non Global Names
Question: In Python Version: 2.7.5, I have Zelle's Graphics installed and I have no idea
what to do because I am trying to edit a non global name in a function with a
different function. Here is an example of my code.

    
    
    from graphics import *
    import time
    keyPad=GraphWin("Key Pad",300,400)
    def Game():
        Buttons()
        testFor_keyPad_press()
    def Buttons():
        button1=Rectangle(Point(1,1),Point(100,100))
        button1.setFill('gold')
        button.draw(keyPad)
    def testFor_keyPad_press():
        userInput=keyPad.getMouse()
        userInputX=str(userInput.getX())
        userInputY=str(userInput.getY())
        if(userInputX<101 and userInputY<100):
            button1.setFill('grey')
            keyPad.update()
            time.sleep(0.5)
            button1.setFill('gold')
            keyPad.update()
    Game()
    

I thought that should work, but it gives me an error saying that global name
'button1' is not defined... so is there a way I can edit button1 inside of the
user defined function "Buttons()" ? Or is that not possible? Please let me
know if there is a way to do this or not... all help is


Answer: 
    def Buttons():
        global button1
        button1=Rectangle(Point(1,1),Point(100,100))
        button1.setFill('gold')
        button.draw(keyPad)
    

would make it accessible outside the function ... but really you should
probably encapsulate your logic in classes

