tmbo/questionary

How to navigate back at start screen?

kmeans27 opened this issue · 2 comments

Question

Hello,

I am currently trying to get used to questionary. As far as now I really like this library!

However I have a question on how to navigate one step backwards.

Here is the sample code:

navigation = questionary.select("Select one of the following:",
                                    choices=[
                                        "A",
                                        "B",
                                        "C",
                                        "D",
                                        "E",
                                        "F",
                                        "G"
                                    ]).ask()

    if navigation == "G":
        choice = questionary.confirm("Are you sure?").ask()
        if choice == "Yes":
            exit()
        else:

note here I do not know what to put in the else statement. All I want the application to do is go one question back. So the user can again "Select one of the following:"

What have you already tried?

no idea, sorry

Read the documentation

  • I have checked to ensure that my question is not answered by the documentation.

Hi, assuming you mean "redo the question" by "go one question back",
all you need to do is put the code in a while loop, like this:

while True:
    navigation = questionary.select("Select one of the following:",
                                    choices=[
                                        "A",
                                        "B",
                                        "C",
                                        "D",
                                        "E",
                                        "F",
                                        "G"
                                    ]).ask()

    if navigation == "G":
        choice = questionary.confirm("Are you sure?").ask()
        if choice == "Yes":
            exit()

No else required.
Note that exit() and quit() don't seem to really work, for some reason probably questionary-related
I hope this helped!

Hi @kmeans27. I'll close this issue now, as I think @mrHeavenli's answer should help you. If not, post back here and I can reopen it.