# Python Processing 3

**URL:** <https://discourse.processing.org/t/python-processing-3/17057>\
**Category:** Processing.py\
**Created:** [January 13, 2020, 2:11am UTC](https://discourse.processing.org/t/python-processing-3/17057 "2020-01-13T02:11:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![heyitsme](https://avatars.discourse-cdn.com/v4/letter/h/7cd45c/32.png) [@heyitsme](https://discourse.processing.org/u/heyitsme)\
**Post date:** [January 13, 2020, 2:11am UTC](https://discourse.processing.org/t/python-processing-3/17057/1 "2020-01-13T02:11:38Z")

</div>

My code isn’t working and I don’t know why.  
My start button and my control button works fine, but the arrow button, to go back to the menu, at my control button wouldn’t work.  
Please help!  
Here is my code:

```auto
def setup():
    global menu, controls, whatever
    size (750, 750)
    menu = loadImage ( "startmainmenu.jpg" )
    controls = loadImage ( "keycontrols.jpg" )
    whatever = loadImage ( "gameover.jpg" )

def draw():
    image(menu, 0, 0, 750, 750)

#startbutton
def mouseReleased(s):
    if s.x > 136 and s.x < 136 + 477 and s.y > 263 and s.y < 263 + 159:
        image(whatever, 0, 0, 750, 750)
        noLoop()

#controlbutton
def mousePressed(c):
    if c.x > 136 and c.x < 136 + 477 and c.y > 484 and c.y < 484 + 159:
        image(controls, 0, 0, 750, 750)
        noLoop()

        #arrowbutton
        def mouseClicked(a):
            if a.x > 0 and a.x < 0 + 61 and a.y > 672 and a.y < 672 + 77:
                image(menu, 0, 0, 750, 750)
                noLoop()

```

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [January 13, 2020, 6:47am UTC](https://discourse.processing.org/t/python-processing-3/17057/2 "2020-01-13T06:47:47Z")

</div>

You need to out-dent your `def mouseClicked(a)` code, so that it sits against the left margin. Currently, it’s nested within the `mousePressed(c)` block.

I’ve spotted another issue, though: your `#startbutton` and `#controlbutton` code are always active. In other words, when your “whatever” and “controls” images are showing, the startbutton and controlbutton ‘zones’ remain clickable.

---

<div class="post-metadata">

**Author:** ![heyitsme](https://avatars.discourse-cdn.com/v4/letter/h/7cd45c/32.png) [@heyitsme](https://discourse.processing.org/u/heyitsme)\
**Post date:** [January 14, 2020, 1:32am UTC](https://discourse.processing.org/t/python-processing-3/17057/3 "2020-01-14T01:32:45Z")

</div>

how would you make the buttons unactive?

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [January 14, 2020, 2:27am UTC](https://discourse.processing.org/t/python-processing-3/17057/4 "2020-01-14T02:27:29Z")

</div>

You need a structure for managing different levels/states in your game. Something to manage the switch between the different menus, between your menu and level 1 (with it’s own control scheme), the end-game screen, etc.

There are many approaches you can take … the ideal solution depends on how complex your game is and how well you know Python/Processing. Here’s the simplest example I can whip up:

```auto
state = 'menu'

def setup():
    size(750, 750)

def draw():
    background(0)

    if state == 'menu':
        text('CLICK TO GO TO WHATEVER', 100, 100)
        
    elif state == 'whatever':
        text('CLICK TO GO TO MENU', 100, 100)
        
    elif state == 'level1':
        ...

def mouseClicked(e):
    global state
    
    if state == 'menu':
        # mouse events for menu
        if e.x > 80 and e.x < 290 and e.y > 70 and e.y < 120:
            state = 'whatever'
            print(114235)

    elif state == 'whatever':
        # mouse events for controls
        if e.x > 80 and e.x < 290 and e.y > 70 and e.y < 120:
            state = 'menu'
            
    elif state == 'level1':
        ...
        

```

Hope this helps.

If you’re doing advanced menu stuff, you may want to look at a GUI library.

---

<div class="post-metadata">

**Author:** ![snakey](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@snakey](https://discourse.processing.org/u/snakey)\
**Post date:** [April 7, 2022, 2:47am UTC](https://discourse.processing.org/t/python-processing-3/17057/5 "2022-04-07T02:47:41Z")

</div>

Beginner here. I was struggling over the same problem for a very long time and your answer just saved my life. Thank you so much!!!
