Skip to content

Instantly share code, notes, and snippets.

@ThomasPickering
Last active April 13, 2023 05:42
Show Gist options
  • Select an option

  • Save ThomasPickering/64676d4f8cb1fecc91889da35f3f55c5 to your computer and use it in GitHub Desktop.

Select an option

Save ThomasPickering/64676d4f8cb1fecc91889da35f3f55c5 to your computer and use it in GitHub Desktop.
Python : Simple CLI Menu
def main_menu():
while True:
print("Main menu:")
print(" 1. Submenu 1")
print(" 2. Submenu 2")
print(" 3. Exit")
choice = input("Enter your choice: ")
if choice == "1":
submenu1()
elif choice == "2":
submenu2()
elif choice == "3":
print("Exiting...")
break
else:
print("Invalid choice. Please try again.")
def submenu1():
while True:
print("Submenu 1:")
print(" 1. Option 1")
print(" 2. Option 2")
print(" 3. Back to main menu")
choice = input("Enter your choice: ")
if choice == "1":
# do something
pass
elif choice == "2":
# do something else
pass
elif choice == "3":
print("Returning to main menu...")
break
else:
print("Invalid choice. Please try again.")
def submenu2():
# similar to submenu1()
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment