No need to use Python. This is more a question of organization.
I'm not sure if I understand your setup correctly. So I want to rephrase it a bit. That way it might help you to find out how to get what you want.
History menu
... when you press the History Mode button it makes the empty slide the left menu to the right
- Initial the history menu is located left of the screen (collapsed position).
- On a "show history" request - the history menu moves from collapsed position to the expand position at the left side of the screen showing as "left menu"
when you press the back button that is at the bottom of the right menu, it makes you return to the start menu by sliding the left menu to the right
- On a "hide history" request - the history menu moves from expand position to collapsed position (where the request is coming from does not matter at that stage)
Implementation option:
- play a "showing history menu" action in flipper mode

Now you can play the action by switching the property:

Hint: you see I do not relate on key press here. This allows me to map any event to a request (keyboard button, screen button, joystick button, or even programmatic created event). You will need that later.
Inventory menu
inventory is the right menu
This can use the same method to be presented:
- Initial the inventory menu is located right of the screen (collapsed position).
- On a "show inventory" request - the inventory menu moves from collapsed position to the expand position at the right side of the screen showing as "right menu"
- On a "hide inventory" request - the inventory menu moves from expand position to collapsed position (where the request is coming from does not matter at that stage)
Implementation option:
- play a "showing inventory menu" action in flipper mode
The logic is all the same as of the history menu, just the requests (events) and the action are different.
Goals menu
The same again.
- "show goals": move from collapsed position to expand position
- "hide goals": move from expanded position to collapsed position

Consolidation
As you want both the history menu as well as the goals menu to use the same collapse and expand position you could use the same action. I suggest to rename it to "showing left menu" or similar.
According to that I suggest to rename the action of the inventory menu to "showing right menu".
This abstracts the specific menu positions from "history, inventory, goals" to "left and right" positions.
Exclusive menus
As you have two left menus (history and goals) right now, you have the wish to show only one of them at the time. This creates a dependency between the menus of the left menu.
So lets analyse this a little bit deeper. What different situations can we think of with left menu?
- left menu is collapsed
- left menu is expanded and shows history menu
- left menu is expanded and shows goals menu
(Note: the left menu never shows goals menu and history menu at the same time.)
Nested menus
Here I suggest to introduce a left menu.
The left menu can have three different states:
To switch between the different modes you need different requests:
- "hide left menu"
- "show history in left menu"
- "show goals in left menu"
As the single menus already know how to expand and collapse you can trigger that:
- on "hide left menu"
- request "hide history menu"
- request "hide goals menu"
- on "show history in left menu"
- request "show history menu"
- request "hide goals menu"
- on "show goals in left menu"
- request "hide history menu"
- request "show goals menu"
It would be helpful when you "request" by message rather than by keyboard sensor as there is no logic brick that presses keys.
Implementation suggestion
One object acts as left menu and deals with the left menu requests.



Just for completeness here is my implementation of a keyboard UI. I'm sure your will make use of your on screen buttons.

Remarks:
- There are several other options to implement such a behavior. This is just one of them.