How to Create a Simple Menu Maker for Python Scripts
The aim of this page📝 is to share a module I’m using for creating a simple menu in Python scripts.
1 min readMar 8, 2023
Let’s see the CIA (code-in-action:) first
First, put the following code into a dedicated module
- It’s just a class that creates an object with list of menu items and has a printer method and a simple selector
Then, in your script, import
it ⟹ initialize
with a list of options ⟹ print_menu
⟹ and select_menu_item
- Import your
menu_maker
(not going into the weeds of importing here) - It takes a
list
of items, for example
- The
select_menu_item()
maps the numerical input to the proper name of the menu item —Delete
is1
;Patch
is2
; etc. - And that’s all… in my case, I continue with your selection whatever you please, e.g. I’m calling dedicated functions with readable code
- Since it takes a list, you can dynamically generate menu items, too (like I am using a base name of files for certain menu items ⟹ you can map them to template files in your folder, etc.)