To allow users to select multiple items, pass multi_select=True to the constructor.
Usage:
- Use
space or tab to toggle selections. - Press an accept key to finish. The
show() method returns a sorted tuple of indices. - Use the
chosen_menu_entries property to get the actual strings of the selected items.
Configuration:
multi_select_keys: Custom keys to toggle items (default: " ,tab").show_multi_select_hint=True: Shows a hint in the status bar.multi_select_select_on_accept=False: If False, the currently highlighted item is NOT automatically added to the selection upon pressing the accept key.multi_select_empty_ok=True: Allows returning an empty selection if no items were explicitly selected.preselected_entries: An iterable of integers (indices) or strings (matching entry text) to pre-select items on startup.
from simple_term_menu import TerminalMenu
def main():
terminal_menu = TerminalMenu(
["dog", "cat", "mouse", "squirrel"],
multi_select=True,
show_multi_select_hint=True,
)
# Returns a tuple of indices, e.g., (0, 2)
menu_entry_indices = terminal_menu.show()
# Returns a tuple of strings, e.g., ("dog", "mouse")
print(terminal_menu.chosen_menu_entries)
if __name__ == "__main__":
main()