简体   繁体   中英

How to create a command “home” or “quit” that returns to the main function of a program in python

I have a program that displays a "main menu" with several options for users and then starts a method when an option is selected. Eg If you select "Add Name" the add_name method is executed and then the main menu is displayed again.

Inside each of the methods you can access from the menu are several prompts. Eg Inside of "Add Name" is the prompt "Add which name?".

I would like the user to be able to type "help" or "quit" from any prompt anywhere in the program and have the program display a help menu in the first case or return to the main menu in the second.

Is this possible? How would a program like that be structured?

听起来您需要用于控制台模式的结构化菜单绘制系统,例如cursesurwid

一种简单的方法是创建一个定义,该定义在用户每次输入值时都专门查找这些输入,并让其在任何其他定义之前执行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM