Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在控制台中使输入文本加粗?_Python_Python 3.x - Fatal编程技术网

Python 如何在控制台中使输入文本加粗?

Python 如何在控制台中使输入文本加粗?,python,python-3.x,Python,Python 3.x,我正在寻找一种方法,使用户在控制台中键入的文本加粗 input("Input your name: ") 如果我输入“John”,我希望它显示得和我输入的一样粗体,类似这样的 输入您的姓名:John 它们被称为ANSI转义序列。基本上,您可以输出一些特殊的字节来控制终端文本的外观。试试这个: x = input('Name: \u001b[1m') # anything from here on will be BOLD print('\u001b[0m', end='') # anyt

我正在寻找一种方法,使用户在控制台中键入的文本加粗

input("Input your name: ")
如果我输入“John”,我希望它显示得和我输入的一样粗体,类似这样的

输入您的姓名: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转义序列。

这有用吗?@yosukesabai它只在使用print()打印东西时有效,我希望它在控制台中键入时立即显示为粗体。另外,我已经看到了这一点,没有帮助,但感谢您,您是否使用linux?stty可能可以将您的输出更改为粗体。我在windows上。同样,我并不是真的在寻找以粗体打印文本的方法。我正在寻找将输入文本变为粗体的方法。但是,谢谢您k你!我知道ansi转义序列,但我不知道你可以这样使用它们