aegirhall / console-menu

A simple Python menu system for building terminal user interfaces.
MIT License
365 stars 58 forks source link

Variable Value Extracton #57

Closed WarpWing closed 3 years ago

WarpWing commented 3 years ago

Is it possible I could get a variable from

function_item = FunctionItem("Call a Python function", input, ["Enter an input"])

so that I can use it as input in my functions?

nlemarodriguez commented 3 years ago

How did you resolve this? @WarpWing I have the same question, I need to get value from an user input...

WarpWing commented 3 years ago

How did you resolve this? @WarpWing I have the same question, I need to get value from an user input...

I didn't. I just called a function from the menu and had that function handle user input like so. Yeah the library can be a bit confusing so for my use case I just adapted it to work with functions

launchMP = FunctionItem("Create New MP Instance", launchMPI)
def launchMPI():
    print("What would like to name this MP Instance?")
    mpname = input("Name: ")
nlemarodriguez commented 3 years ago

Thanks for your help. I used a similar approach:

# Dict with variables, default values are empty
variables = {'account': '', 'folder': '', 'number_files': 0}
# Set account
account_set = FunctionItem("Cuenta de donde quieres realizar la descarga de contenido", input_user,
                          ['account', "Nombre de la cuenta: "])

def input_user(var, text):
    s = input(text)
    variables[var] = s

In variables dict I stored a few inputs from user, so I have others variables FunctionItem that called the same function _inputuser(var, text) in order to store the inputs.

I agree with you, it's a bit confusing, but it's a good library anyway.