用于更改python控制台的文本颜色和背景的综合实用程序库。
Color-Console的Python项目详细描述
最大加载颜色控制台
此模块用于更改为windows操作系统设计的python控制台的文本颜色和背景色。
有什么新消息?=>;更容易导入功能。
=>;已更新功能以使用词典。
=>;又增加了4个功能。
=>;不可用库的自动软件包安装。
=>;参数不区分大小写。
=>;提高了错误容忍度。
导入函数:
from color_console import*
语句用于从color_console模块导入所有必需的功能。
此版本包含以下功能,我们稍后将讨论这些功能。
$颜色()
$ctext()
$传输时间()
$hackerman()
$帮助()
颜色()
color()
用于更改整个python控制台的文本颜色和背景色。
颜色(text="Bright White",bg="Black",延迟=0.67,repeat=-1,dict={})
是函数头。
文本
用于指定文本的颜色。
bg
用于指定背景颜色。
允许的颜色为:
<H4>1。黑色
<H4>2。蓝色
<H4>3。绿色
<H4>4。浅绿色
5。红色
<H4>6。紫色
<H4>7。黄色
<H4>8。白色
<H4>9。灰色
<H4>10。浅蓝色
<H4>11。浅绿色
<H4>12。浅绿色
<H4>13。浅红色
<H4>14。浅紫色
<H4>15。浅黄色
<H4>16。亮白色没有一个参数区分大小写。文本颜色和背景颜色不能相同。
如果允许的颜色列表传递给文本或bg,则颜色会根据它们在列表中的位置而变化。
# Constant background color with altering text color:li=['black','bright white']print("Hello World !")color(li,'aqua')# This will make the text color of the console change to black and bright white alternatively and indefinitely# with it's background color set to aqua
# Constant text color with altering background color:li=['black','bright white']print("Hello World !")color('aqua',li)# This will make the background color of the console change to black and bright white alternatively and indefinitely# with it's text color set to aqua
延迟
参数用于指定两次转换之间的时间。默认值设置为0.67秒,可以更改。
# Changing color transition time:li=['black','bright white']print("Hello World !")color('aqua',li,delay=1)# and hence the color transition would take 1 second.
repeat
参数用于指定颜色列表必须重复的次数。默认值是-1,这使得颜色转换无限期地发生。注意,如果颜色转换设置为不确定,程序将不会进一步移动(它旁边的代码将不会执行!).repeat
参数将允许在列表迭代给定次数后继续执行代码。所需时间取决于延迟时间和重复时间。
# repeating the color transition only certain number of timesli=['black','bright white']print("Hello World !")color('aqua',li,delay=1,repeat=2)# The transition will be repeated two times with a time delay of 1 second each and hence would take 4 seconds# since the number of elements in the list is 2.
完成转换所需的总时间可以使用transtime()
找到,稍后将对其进行说明。
延迟
和重复
是可选参数。
列出"text"和"bg"的参数时,颜色转换如下:
# When both text and bg recieve arguements that are of list type,# the corresponding text and bg colors are used as they are iteratedprint("Hello World")color(['green','blue'],['black','bright white'])# This would result in a console with the following text and bg color which repeats indefinitely# green text color with black as bg color# blue text color with bright white as bg color
请注意,如果两个列表的大小不同,将抛出一个错误。
可以将具有有效颜色组合的词典传递到dict,从而使用两个列表获得与前一个类似的输出。
# Passing dictionary to color()Dictionary={'green':'black','blue':'bright white'}color(dict=Dictionary)# This output is similar to the previous one.
传递字典的限制:
键中的颜色不能出现在值中。所以不要把字典里的键和值混在一起。
提醒:字典={key1:value1,key2:value2}字典由键:值对组成
Dictionary={'green':'black','black':'bright white'}print("Hello World")color(dict=Dictionary)# This code would throw an error since 'black' is both in keys and values of the dictionary.
Dictionary={'red':'bright white','black':'bright white'}print("Hello World")color(dict=Dictionary)# This code wouldn't throw an error since 'bright white' is only values and not in keys of the dictionary.
因此允许颜色重复,但不允许键和字典值混合!
ctext()
ctext()
用于更改python控制台中仅一行的文本和背景色。
ctext(string,text="white",bg="black",delay=0,repeat=1,dict={})
是函数头。
字符串
用于发送需要着色的字符串。
文本
用于指定文本的颜色。
bg
用于指定背景颜色。
允许的颜色为:
<H4>1。蓝色
<H4>2。绿色
<H4>3。红色
<H4>4。洋红色
5。黄色
<H4>6。白色
<H4>7。青色
<H4>8。黑色仅用于背景没有一个参数区分大小写。文本颜色和背景颜色不能相同。
< Buff行情>注意:ctext()
需要两个模块工作,即colorama
和termcolor
。
无论何时运行ctext,都会自动验证并导入这两个模块。如果没有这两个模块,则通过PIP自动安装。在这种情况下,建议使用良好的互联网连接。如果安装过程失败,即使在有Internet的情况下(程序会通知您!),请尝试通过PIP手动安装这两个模块。
CText与颜色的相似性:
类似于text
、bg
、delay
、repeat
和dict
的参数以类似的方式工作,但会有一些小的异常,稍后将讨论这些异常。
例外情况:
字符串
参数将字符串作为参数,并且该行单独按文本和bg参数的指示打印不同的颜色。将字符串单独传递给ctext()
类似于print()
语句。
字符串
参数是必需的,不应省略"
ctext("Hello World","Green",'white')# This would affect only this line unlike color()ctext("Hello World")# This statement is similar to print()
允许的颜色对于color()
和ctext()
是不同的,上面已经提到过了
延迟是指在列表中打印连续语句之间的时间。当一个列表被传递给文本或bg时,根据参数repeat,将以相应的颜色逐个打印字符串。默认值延迟
设置为0个单位,重复
设置为1
transtime()
transtime
用于查找完成所有颜色转换所需的总时间。只有在所有转换完成后,才会执行下面的代码color()
或ctext()
。
transtime(n,delay,repeat,print=true)
是函数头。
可以将"列表或词典中的颜色数"或"列表和词典本身"传递给n
延迟
参数接受您计划使用的延迟值。
重复>参数取您计划使用的延迟值。
此函数同时打印并返回总转换时间。不使用返回值不会引发错误。
print
是一个可选参数,默认设置为true。如果更改为false,transtime()
将只返回一个值,而不会在控制台上打印任何内容。
# Constant background color with altering text color:li=['black','bright white']print("Hello World !")color(li,'aqua')# This will make the text color of the console change to black and bright white alternatively and indefinitely# with it's background color set to aqua
0
hackerman()
添加此功能只是为了好玩,以防您希望在朋友中看起来像黑客。
这将使文本颜色变为"绿色",背景变为"黑色"。
这不需要争论。只需在程序开始时添加此函数!
# Constant background color with altering text color:li=['black','bright white']print("Hello World !")color(li,'aqua')# This will make the text color of the console change to black and bright white alternatively and indefinitely# with it's background color set to aqua
1
帮助()
help()
将在脱机的python控制台中为您提供相同的信息
帮助(c=true)
是函数头。
如果使用help()
文本和背景将在30秒后根据预定义的颜色指示自动更改。如果您发现它令人不安,可以使用帮助(false)
关闭颜色转换并以默认颜色显示说明。
由Sayad Pervez开发
电子邮件ID:pervez2504@gmail.com">pervez2504@gmail.com
推荐PyPI第三方库
from color_console import*
语句用于从color_console模块导入所有必需的功能。color()
用于更改整个python控制台的文本颜色和背景色。颜色(text="Bright White",bg="Black",延迟=0.67,repeat=-1,dict={})
是函数头。文本
用于指定文本的颜色。bg
用于指定背景颜色。延迟
参数用于指定两次转换之间的时间。默认值设置为0.67秒,可以更改。repeat
参数用于指定颜色列表必须重复的次数。默认值是-1,这使得颜色转换无限期地发生。注意,如果颜色转换设置为不确定,程序将不会进一步移动(它旁边的代码将不会执行!).repeat
参数将允许在列表迭代给定次数后继续执行代码。所需时间取决于延迟时间和重复时间。
# repeating the color transition only certain number of timesli=['black','bright white']print("Hello World !")color('aqua',li,delay=1,repeat=2)# The transition will be repeated two times with a time delay of 1 second each and hence would take 4 seconds# since the number of elements in the list is 2.
完成转换所需的总时间可以使用transtime()
找到,稍后将对其进行说明。
延迟
和重复
是可选参数。
列出"text"和"bg"的参数时,颜色转换如下:
# When both text and bg recieve arguements that are of list type,# the corresponding text and bg colors are used as they are iteratedprint("Hello World")color(['green','blue'],['black','bright white'])# This would result in a console with the following text and bg color which repeats indefinitely# green text color with black as bg color# blue text color with bright white as bg color
请注意,如果两个列表的大小不同,将抛出一个错误。
可以将具有有效颜色组合的词典传递到dict,从而使用两个列表获得与前一个类似的输出。
# Passing dictionary to color()Dictionary={'green':'black','blue':'bright white'}color(dict=Dictionary)# This output is similar to the previous one.
传递字典的限制:
键中的颜色不能出现在值中。所以不要把字典里的键和值混在一起。
提醒:字典={key1:value1,key2:value2}字典由键:值对组成
Dictionary={'green':'black','black':'bright white'}print("Hello World")color(dict=Dictionary)# This code would throw an error since 'black' is both in keys and values of the dictionary.
Dictionary={'red':'bright white','black':'bright white'}print("Hello World")color(dict=Dictionary)# This code wouldn't throw an error since 'bright white' is only values and not in keys of the dictionary.
因此允许颜色重复,但不允许键和字典值混合!
ctext()
ctext()
用于更改python控制台中仅一行的文本和背景色。
ctext(string,text="white",bg="black",delay=0,repeat=1,dict={})
是函数头。
字符串
用于发送需要着色的字符串。
文本
用于指定文本的颜色。
bg
用于指定背景颜色。
允许的颜色为:
<H4>1。蓝色
<H4>2。绿色
<H4>3。红色Dictionary={'green':'black','black':'bright white'}print("Hello World")color(dict=Dictionary)# This code would throw an error since 'black' is both in keys and values of the dictionary.
Dictionary={'red':'bright white','black':'bright white'}print("Hello World")color(dict=Dictionary)# This code wouldn't throw an error since 'bright white' is only values and not in keys of the dictionary.
因此允许颜色重复,但不允许键和字典值混合!
ctext()
ctext()
用于更改python控制台中仅一行的文本和背景色。
ctext(string,text="white",bg="black",delay=0,repeat=1,dict={})
是函数头。
字符串
用于发送需要着色的字符串。
文本
用于指定文本的颜色。
bg
用于指定背景颜色。
允许的颜色为:
<H4>1。蓝色ctext()
需要两个模块工作,即colorama
和termcolor
。
无论何时运行ctext,都会自动验证并导入这两个模块。如果没有这两个模块,则通过PIP自动安装。在这种情况下,建议使用良好的互联网连接。如果安装过程失败,即使在有Internet的情况下(程序会通知您!),请尝试通过PIP手动安装这两个模块。text
、bg
、delay
、repeat
和dict
的参数以类似的方式工作,但会有一些小的异常,稍后将讨论这些异常。字符串
参数将字符串作为参数,并且该行单独按文本和bg参数的指示打印不同的颜色。将字符串单独传递给ctext()
类似于print()
语句。字符串
参数是必需的,不应省略"color()
和ctext()
是不同的,上面已经提到过了
延迟是指在列表中打印连续语句之间的时间。当一个列表被传递给文本或bg时,根据参数repeat,将以相应的颜色逐个打印字符串。默认值延迟
设置为0个单位,重复
设置为1
字符串。默认值延迟
设置为0个单位,重复
设置为1
transtime()
transtime
用于查找完成所有颜色转换所需的总时间。只有在所有转换完成后,才会执行下面的代码color()
或ctext()
。
transtime(n,delay,repeat,print=true)
是函数头。
可以将"列表或词典中的颜色数"或"列表和词典本身"传递给n
延迟
参数接受您计划使用的延迟值。
重复>参数取您计划使用的延迟值。
此函数同时打印并返回总转换时间。不使用返回值不会引发错误。
print
是一个可选参数,默认设置为true。如果更改为false,transtime()
将只返回一个值,而不会在控制台上打印任何内容。
# Constant background color with altering text color:li=['black','bright white']print("Hello World !")color(li,'aqua')# This will make the text color of the console change to black and bright white alternatively and indefinitely# with it's background color set to aqua0
hackerman()
添加此功能只是为了好玩,以防您希望在朋友中看起来像黑客。
这将使文本颜色变为"绿色",背景变为"黑色"。
这不需要争论。只需在程序开始时添加此函数!
# Constant background color with altering text color:li=['black','bright white']print("Hello World !")color(li,'aqua')# This will make the text color of the console change to black and bright white alternatively and indefinitely# with it's background color set to aqua1
帮助()
help()
将在脱机的python控制台中为您提供相同的信息
帮助(c=true)
是函数头。
如果使用help()
文本和背景将在30秒后根据预定义的颜色指示自动更改。如果您发现它令人不安,可以使用帮助(false)
关闭颜色转换并以默认颜色显示说明。
由Sayad Pervez开发
电子邮件ID:pervez2504@gmail.com">pervez2504@gmail.com
帮助(c=true)
是函数头。help()
文本和背景将在30秒后根据预定义的颜色指示自动更改。如果您发现它令人不安,可以使用帮助(false)
关闭颜色转换并以默认颜色显示说明。