tags:

views:

37

answers:

1

Modify the main function to call getAction right after the win.getMouse() call inside of the while loop. Store the return value in a variable named action, and use print to display the value returned.

This is my code so far. What I'm having trouble with is how to return the value in a variable named action, and then use print to display the value returned.

ACTION_PET = 1
ACTION_FEED = 2
ACTION_PLAY = 3
ACTION_IGNORE = 4
ACTION_ERROR = 5

def getAction():

    win = GraphWin("CS1400 - Pet Dog", 610, 500) 
    clear_screen(win)                            
    rec1, rec2, rec3, rec4= draw_buttons(win)
        while True:
            mouseClick = win.getMouse()                  

            if inBox(rec1, mouseClick):
                ACTION_PET(win)                            
            elif inBox(rec2, mouseClick):
                ACTION_FEED(win)                            
            elif inBox(rec3, mouseClick):
                ACTION_PLAY(win)                         
            elif inBox(rec4, mouseClick):
                ACTION_IGNORE(win)
            else:
                ACTION_ERROR(win)

                break                  


# main program

def main():
    """dog drawing program"""

    win = GraphWin("CS1400 - Pet Dog", 610, 500)      # create graphics window
    clear_screen(win)                                # start with a clear screen
    rec1, rec2, rec3, rec4= draw_buttons(win)        # create user buttons

    # loop forever until cat is dead
    while True:
        mouseClick = win.getMouse()
                                                     # get mouse click

        if inBox(rec1, mouseClick):
            drawHappy(win)                            # draw happy dog
        elif inBox(rec2, mouseClick):
            drawAngry(win)                            # draw angry dog
        elif inBox(rec3, mouseClick):
            drawSleeping(win)                         # draw sleeping dog
        elif inBox(rec4, mouseClick):
            drawBored(win)                            # draw bored dog

            break



    # wait for user to click one more time before ending the program
    msg_location = Point(305, 430)
    msg = Text(msg_location, "Click anywhere to quit.")
    msg.setTextColor("red")
    msg.draw(win)                         # draw message

    win.close()
    return
A: 

You have lots of things (apparently) wrong with your code.

ACTION_PET(win) will give you a TypeError: 'int' object is not callable

return the value in a variable named action What value?

if inBox(rec1, mouseClick): Where is inBox() defined?


if inBox(rec1, mouseClick):
            drawHappy(win)                            # draw happy dog
        elif inBox(rec2, mouseClick):
            drawAngry(win)                            # draw angry dog
        elif inBox(rec3, mouseClick):
            drawSleeping(win)                         # draw sleeping dog
        elif inBox(rec4, mouseClick):
            drawBored(win)     

None of those are defined either.

Falmarri