I have a idea to create a console select menu in python like this:
Choose an option:
> 1. Do something 1 <
2. Do something 2
3. Do something 3
4. Do something 4
If I press up arrow key, nothing happens. If I press the down one, the less than and greater than symbol would move up and down like this:
Choose an option:
1. Do something 1
> 2. Do something 2 <
3. Do something 3
4. Do something 4
But I dont know which Python 3 module would help me catch the key press instead of input()
, and idk how I can align it correctly.
My solution for alignment is to print spaces (maybe?) and when the key press event is catches, the console will be cleared and it prints the select menu again instead of changing/modifying the strings.
Also, the options would be get from a list, which means this menu is expandable
I wrote a Python module pick
for this, it has an easy to use api and supports Windows
https://github.com/wong2/pick
from pick import pick
title = 'Please choose your favorite programming language: '
options = ['Java', 'JavaScript', 'Python', 'PHP', 'C++', 'Erlang', 'Haskell']
option, index = pick(options, title, indicator='=>', default_index=2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With