简体   繁体   中英

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.

在此处输入图像描述

Thank You

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']) 

No, it is generally not. For an easy gui look up easy gui , or you might be looking for raw input , where you can type your answer, for example

Want to do something? (Y/N)_ Y

There is beaupy , which allows you to do something like this:

from beaupy import select_multiple
    
pizza_toppings = select_mutliple(['pineapple', 'olives', 'anchovies', 'mozzarella', 'parma ham']
                                 maximal_count=3,
                                 minimal_count=1)

Note: I am a maintainer of beaupy and this is nothing short of shameless self-promotion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM