asweigart/pyinputplus

inputMenu function does not display the menu if prompt option is specified

mark-turner opened this issue · 2 comments

Hey @asweigart, I took your course on Udemy and frequently use your book as a reference. Thanks for both!

The issue I'm seeing is that if I specify a custom prompt, the menu is not displayed. For example, the following works:

>>> response = pyip.inputMenu(['dog','cat'], numbered=True)
Please select one of the following:
1. dog
2. cat
1

But this does not:

>>> response = pyip.inputMenu(['dog','cat'], prompt='My custom prompt:', numbered=True)
My custom prompt:3
'3' is not a valid choice.
Select one of the following:1

As you can see, only the prompt is displayed in the second case.

Obviously this is easy to work around by simply printing the menu myself, but I thought you'd like to know.

Actually, this is by design for inputMenu(). If you supply no prompt, it displays the numbered choices. However, if the user is displaying a prompt, we don't want to make any assumptions about how they display the menu itself. For example, if they wanted to display all the numbered choices on one line, instead of one line per choice, they can set the prompt that way.

It's a bit annoying if you only want to replace the "Please select one of the following:" text and not the numbered choices, but if we always included that, then it'd be impossible to have a different display AND let the user enter numbers.

Thanks @asweigart. I don't quite follow your reasoning, but fair enough. Might be an idea to document the behavior though ;-)