Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Command Line Checkboxes

I am new to Python 2.7 but I was wondering if it is possible to have checkboxes that are selectable by a user via the command line.

The only example I know of is yeoman (below) but its probably not written in Python.

enter image description here

Thank You

like image 558
arduima Avatar asked May 20 '14 23:05

arduima


1 Answers

Have a look at the python-inquirer package.

To make a checkbox list you can do something like this:

import inquirer

questions = [inquirer.Checkbox(
    'interests',
    message="What are you interested in?",
    choices=['Computers', 'Books', 'Science', 'Nature', 'Fantasy', 'History'],
)]
answers = inquirer.prompt(questions)  # returns a dict
print(answers['interests']) 
like image 108
Dan P. Avatar answered Oct 05 '22 01:10

Dan P.