How to Print a Menu in Python

Ryan Jul 16, 2026

Printing a menu in Python is a common task when working with command-line applications. Typically, a menu displays options for users to interact with the program. Here's how you can print a menu using Python.

Python GUI with Tkinter - 9 - Creating Drop Down Menus
Python GUI with Tkinter - 9 - Creating Drop Down Menus

We'll explore two primary methods: using the built-in print() function and creating a custom function for more sophisticated menu structures. Let's dive into each approach.

30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast
30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast

Using print() function

The most straightforward way to display a menu is by using the print() function, which outputs the content to the console. To create a simple menu, we can separate each option with a line break.

Adding Menus to Python 3 tkinter GUI Programs - EasyCodeBook.com
Adding Menus to Python 3 tkinter GUI Programs - EasyCodeBook.com

Here's a simple example of printing a menu with numbers for each option:

```python print("1. Option A") print("2. Option B") print("3. Option C") print("Q. Quit") ```

Advantages and limitations

#7 Python Animated slide menu with navigation buttons, Pyqt5 , Pyside2 | Modern Flat GUI UI
#7 Python Animated slide menu with navigation buttons, Pyqt5 , Pyside2 | Modern Flat GUI UI

This method is easy to understand and implement. However, it has limitations. You can't create nested menus, and styling options are limited. Let's explore a more advanced method for creating menus.

Creating a custom function

For more complex menu structures, you can create a custom function. This function will handle menu display, user input, and navigation between options. We'll use a loop to continuously display the menu until the user chooses to exit.

a paper with some writing on it
a paper with some writing on it

Here's a simple script demonstrating a custom function for a menu:

```python def print_menu(): print("Welcome to our menu:") print("1. Option A") print("2. Option B") print("3. Option C") print("Q. Quit") def main(): while True: print_menu() choice = input("Enter your choice: ").lower() if choice == "q": break elif choice == "1" or choice == "2" or choice == "3": print(f"You chose: {choice}") else: print("Invalid choice. Please try again.") if __name__ == "__main__": main() ```

Sub-topic: Error handling

To enhance the user experience, we can add error handling to manage invalid inputs. In the above script, if the user enters anything other than '1', '2', '3', or 'q', the program will respond with an error message and ask for input again.

Restaurant Billing System Project in Python With Source Code
Restaurant Billing System Project in Python With Source Code

Sub-topic: Enhancing the menu display

For a more appealing menu, consider using ANSI escape codes to apply colors andstyles in the console. Libraries like termcolor can simplify the process. Here's an example:

a menu sitting on top of a wooden table next to a remote control and books
a menu sitting on top of a wooden table next to a remote control and books
Adding a Basic Menu to Tkinter GUI - Arduino Python PySerial - Lesson 6
Adding a Basic Menu to Tkinter GUI - Arduino Python PySerial - Lesson 6
Python GUI Animated Side Menu | Pyside | PyQt | Moder UI | Interface | Drop Down Menu | Flat Style
Python GUI Animated Side Menu | Pyside | PyQt | Moder UI | Interface | Drop Down Menu | Flat Style
How to Print in Python?
How to Print in Python?
Python Programming, Python
Python Programming, Python
How to Create a GUI Restaurant Management Systems in Python - Tutorial 1
How to Create a GUI Restaurant Management Systems in Python - Tutorial 1
Python tkinter Toolbox
Python tkinter Toolbox
a poster with different types of text on it
a poster with different types of text on it
an image of a poster with words and pictures on it that say,'python method for
an image of a poster with words and pictures on it that say,'python method for
Advanced Python Guide
Advanced Python Guide

```python from termcolor import colored def print_menu(): print(colored("Welcome to our menu:", 'cyan')) print(colored("1. Option A", 'blue')) print(colored("2. Option B", 'blue')) print(colored("3. Option C", 'blue')) print(colored("Q. Quit", 'red')) ```

Now that you've seen the basics of printing menus in Python, it's time to apply and customize these methods to fit your specific needs. Remember, menus serve as a crucial interface for guiding users through your application. Make them intuitive, user-friendly, and enjoyable to interact with.