-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLIMenu.py
85 lines (70 loc) · 1.48 KB
/
CLIMenu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sys, os
# Main definition - constants
menu_actions = {}
# =======================
# MENUS FUNCTIONS
# =======================
# Main menu
def main_menu():
os.system('cls')
print("Welcome,\n")
print("Please choose the menu you want to start:")
print("1. Menu 1")
print("2. Menu 2")
print("\n0. Quit")
choice = input(">> ")
exec_menu(choice)
return
# Execute menu
def exec_menu(choice):
os.system('cls')
ch = choice.lower()
if ch == '':
menu_actions['main_menu']()
else:
try:
menu_actions[ch]()
except KeyError:
print("Invalid selection, please try again.\n")
menu_actions['main_menu']()
return
# Menu 1
def menu1():
print ("Hello Menu 1 !\n")
print("9. Back")
print("0. Quit")
choice = input(">> ")
exec_menu(choice)
return
# Menu 2
def menu2():
print("Hello Menu 2 !\n")
print("9. Back")
print("0. Quit")
choice = input(" >> ")
exec_menu(choice)
return
# Back to main menu
def back():
menu_actions['main_menu']()
# Exit program
def exit():
sys.exit()
# =======================
# MENUS DEFINITIONS
# =======================
# Menu definition
menu_actions = {
'main_menu': main_menu,
'1': menu1,
'2': menu2,
'9': back,
'0': exit,
}
# =======================
# MAIN PROGRAM
# =======================
# Main Program
if __name__ == "__main__":
# Launch main menu
main_menu()