Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about using FunctionItem.get_return() #64

Open
davidva-ecco opened this issue Dec 3, 2021 · 0 comments
Open

Question about using FunctionItem.get_return() #64

davidva-ecco opened this issue Dec 3, 2021 · 0 comments

Comments

@davidva-ecco
Copy link

davidva-ecco commented Dec 3, 2021

I'm having trouble figuring out where/how to call FunctionItem.get_return() so that I can display the return data while a ConsoleMenu is running. Here's an example script to help explain what I'm trying to do.

from consolemenu import *
from consolemenu.items import *

def command_1():
    print("Command 1 ran")
    return "Command 1 ran"

def command_2():
    print("Command 2 ran")
    return "Command 2 ran"

def main():
    menu = ConsoleMenu("Root Menu", "This is the Root Menu Subtitle")

    # Create a menu item that calls a function
    function_item_1 = FunctionItem("Command 1", command_1)
    function_item_2 = FunctionItem("Command 2", command_2)

    menu.append_item(function_item_1)
    menu.append_item(function_item_2)

    # Show the menu
    menu.show()

    print(function_item_1.get_return())
    print(function_item_2.get_return())

if __name__ == "__main__":
    main()

With this approach, the text printed to the screen in command_1() and command_2() gets overwritten immediately when the menu redraws. The get_return() prints after menu.show() don't appear until after exiting the menu, which makes sense since menu.show() is blocking. So I have two questions:

  1. Is there a way, using console-menu, to delay redrawing the menu after a FunctionItem's function is called (maybe until another keyboard/enter input) so that anything printed in the function doesn't get overwritten immediately?

  2. Is there a way to do the same as 1 but using function_item_*.get_return() outside of the functions themselves? I'm assuming I need to use another thread but I'm not sure.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant