4

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?

user1447941
  • 3,675
  • 10
  • 29
  • 34
  • This is not something that is easy to do in Python, given that the way console output is displayed is largely dependent on the shell/operating system. However, there are libraries to do this with. If your using Linux/Mac OSX, you can use the `curses`/`ncurses` library. – Joel Cornett Aug 26 '12 at 17:40
  • The script I am creating will be used mostly by Windows users, so I can't use (n)curses. – user1447941 Aug 26 '12 at 17:44

1 Answers1

0

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.

tehmisvh
  • 584
  • 3
  • 9