python - 如何在控制台中使输入文本加粗?
问题描述
我正在寻找一种方法使用户在控制台中键入的文本变为粗体
input("Input your name: ")
如果我输入“John”,我希望它在我输入时显示为粗体,就像这样
输入您的姓名:约翰
解决方案
它们被称为ANSI 转义序列。基本上你输出一些特殊的字节来控制终端文本的外观。尝试这个:
x = input('Name: \u001b[1m') # anything from here on will be BOLD
print('\u001b[0m', end='') # anything from here on will be normal
print('Your input is:', x)
\u001b[1m
告诉终端切换到粗体文本。\u001b[0m
告诉它重置。
本页很好地介绍了 ANSI 转义序列。
推荐阅读
- javascript - 同时调用相同的 this.setState 函数
- json - Delphi XE 格式 json 字符串
- c# - Webapp自动注销问题
- angularjs - 如何在 ng-repeat 中的卡片布局之间留出空间
- vba - 根据另一个单元格的数值更改 x 个单元格的颜色
- html - HTML 字符串中的意外字符导致 WKWebView 问题
- android - 尝试调用虚拟方法 java.lang.String com.activeandroid.TableInfo.getIdName()
- cassandra - 了解 Cassandra - 它可以取代 RDBMS 吗?
- sql-server - Sql server setup 失败:糟糕,检查 sql server setup 规则时出错
- android - Cordova - 使用 android 平台 7 安装插件时出错