0

示例脚本:

import os
import sys
from pprint import pprint
import yaml

sys.path.append(os.path.realpath("."))
import inquirer  # noqa

questions = [
    inquirer.Checkbox(
        "interests",
        message="What are you interested in?",
        choices=["Computers", "Books", "Science", "Nature", "Fantasy", "History"],
        default=["Computers", "Books"],
    ),
]

answers = inquirer.prompt(questions)

pprint(answers)
print(yaml.dump(answers))

产生:

[?] What are you interested in?: 
   X Computers
   o Books

如何将“X”和“o”分别更改为“Y”和“N”?

PS:XOXO 的意思是“拥抱和亲吻”是很普遍的知识,因此在某些工作环境中可能并不合适。

4

1 回答 1

1

您必须定义您的新主题并将其作为参数传递给inquirer.prompt.

这是修改后的代码,将“X”更改为“Y”,将“o”更改为“N”:

import os
import sys
from pprint import pprint

import yaml
from inquirer.themes import Default

sys.path.append(os.path.realpath("."))
import inquirer  # noqa

questions = [
    inquirer.Checkbox(
        "interests",
        message="What are you interested in?",
        choices=["Computers", "Books", "Science", "Nature", "Fantasy", "History"],
        default=["Computers", "Books"],
    ),
]


class WorkplaceFriendlyTheme(Default):
    """Custom theme replacing X with Y and o with N"""

    def __init__(self):
        super().__init__()
        self.Checkbox.selected_icon = "Y"
        self.Checkbox.unselected_icon = "N"


answers = inquirer.prompt(questions, theme=WorkplaceFriendlyTheme())

pprint(answers)
print(yaml.dump(answers))
于 2022-02-07T21:19:04.017 回答