问题
I want to create an "interactive selection" in Python (not sure if I worded that correctly, look at the example below) that lets users press their up and down keys to choose an option and return to confirm it, then it continues with the script. An example output in a terminal would be something like this:
$ python script.py
Please select an option.
[ ] Option 1
[ ] Option 2
[*] Option 3
You have chosen: Option 3
After that first string had printed, the user could use their arrow keys to choose their option marked by the asterisk. The script would look somewhat like this:
print 'Please select an option.'
option = interactive_choice(['Option 1', 'Option 2', 'Option 3'])
print 'You have chosen: ' + option
Anyone know how to do this?
回答1:
You are very limited with these kind of things on Windows. Libraries you may want to look in to are wcurses, PDCurses and Wconsio. Please note I used neither of these libraries myself. You also might be better off designing a GUI with a IDE like Boa Constructor that looks like a terminal, but no doubt that's considerably more difficult.
来源:https://stackoverflow.com/questions/12132333/how-do-i-create-an-interactive-selection