Skip to content
← Back to Community
How to make user to return to main menu in python 3?
Profile icon
[deleted]

I am making a repl that has a main menu and has many options. And I need help with making the user to return to main menu. I tried something like:

Input = input("Enter '1' to return to main menu:")

if Input == '1':
import mainMenu
mainMenu.Run()

In this example, the "mainMenu" module is just a module that has all the options and it will take you back to the main menu. But it does not work. So how do I make the user go back to the main menu? In my repl below, if you try option 1, then return to main menu, nothing happens! Why does this happen?

Answered by seanlnge [earned 5 cycles]
View Answer
Voters
Profile icon
xoxolemcc24215
Comments
hotnewtop
Profile icon
seanlnge

Oh you missed the parentheses in Choice1.py. There should be parentheses next to MainM.Run.

Here is a fixed version

if Choice == 'y': import MainM MainM.Run() else: print("Goodbye")

Hope this helped :)

Profile icon
Bookie0

I don’t know about this mainMenu, what i do is this:

back_to_main_menu = True while back_to_main_menu == True: [your code here for main menu]

Then after, when you want to go back to main menu, for example:

action = input(“press 1 to go back to menu”) if action == “1”: back_to_main_menu = True

And it should take u back to Main menu

please mark this comment as the answer if it helped you :)

Profile icon
[deleted]

@Bookie0 That did not really help, maybe the repl that I posted will help with understanding my problem.

Profile icon
Bookie0

@CarlosRosiles well then I don’t know. You can always use the other way if this one doesn’t work. Idk ...

Profile icon
RGBcode11

IDK