python终端颜色设置
1.颜色定义说明
2.ANSI控制码的说明
3.自定义颜色函数
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author:zml def Colors(text, fcolor=None,bcolor=None,style=None):
'''
自定义字体样式及颜色
'''
# 字体颜色
fg={
'black': '\033[30m', #字体黑
'red': '\033[31m', #字体红
'green': '\033[32m', #字体绿
'yellow': '\033[33m', #字体黄
'blue': '\033[34m', #字体蓝
'magenta': '\033[35m', #字体紫
'cyan': '\033[36m', #字体青
'white':'\033[37m', #字体白
'end':'\033[0m' #默认色
}
# 背景颜色
bg={
'black': '\033[40m', #背景黑
'red': '\033[41m', #背景红
'green': '\033[42m', #背景绿
'yellow': '\033[43m', #背景黄
'blue': '\033[44m', #背景蓝
'magenta': '\033[45m', #背景紫
'cyan': '\033[46m', #背景青
'white':'\033[47m', #背景白
}
# 内容样式
st={
'bold': '\033[1m', #高亮
'url': '\033[4m', #下划线
'blink': '\033[5m', #闪烁
'seleted': '\033[7m', #反显
} if fcolor in fg:
text=fg[fcolor]+text+fg['end']
if bcolor in bg:
text = bg[bcolor] + text + fg['end']
if style in st:
text = st[style] + text + fg['end']
return text
3.1使用方法
from color import Colors
print(Colors('文本内容','字体颜色','背景颜色','字体样式'))
参考:
http://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python
http://blog.csdn.net/gatieme/article/details/45439671
https://taizilongxu.gitbooks.io/stackoverflow-about-python/content/30/README.html
http://www.361way.com/python-color/4596.html
总结:
可以使用python的termcolor模块,简单快捷。避免重复造轮子
from termcolor import colored
print colored('hello', 'red'), colored('world', 'green')
python终端颜色设置的更多相关文章
- Python字体颜色设置
Python字体颜色设置 平时学习工作中,我们经常会接触到一些大佬写的Python工具,运行起来总会显示出五颜六色的字体,比如红色代表Error , 黄色代表Warning , 绿色代表Success ...
- python中颜色设置
实现过程: 终端的字符颜色使用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关. 转义序列是以ESC开头,即用\033来表示(ESC是ASCII码用十进制表示是27,用八进制表示就是033 ...
- MAC 终端颜色设置
在bash中,可以通过更改PS1环境变量的值来设置提示行.通常的提示符颜色单调,用户可以通过在PS1中添加颜色代码序列来设置提示符中不同信息以不同颜色显示. 添加颜色相当容易:第一步是设计不带颜色的提 ...
- python IDLE颜色设置
相信刚学习python的朋友们,都还是挺喜欢python自带的IDLE,但是白的代码背景色以及其它的代码色如何更改呢? Step1:找到config-Highlight.cfg文件,win在C:\Us ...
- ubuntu终端颜色设置
在 .bashrc中增加 PS1='${debian_chroot:+($debian_chroot)}\[\033[00;32m\]\u @ \h\[\033[00m\]:\[\033[00;34m ...
- 一款不错的Linux终端颜色设置
PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m\]]\\$ " #步骤# vi ...
- Linux终端颜色设置
http://blog.sina.com.cn/s/blog_65a8ab5d0101g6cf.html http://www.tuicool.com/articles/NRZfIj #PS1='${ ...
- ubuntu终端颜色配置
对于刚接触ubuntu的同学们,打开终端(ctrl+alt+T),会发现里面都是一个颜色,不管是用户名.主机名还是命令都是白色,当然,用 ls 列出文件的时候是会多一种颜色的.即使这样,对开发人员来说 ...
- Linux终端颜色和标题设置
Linux给人最大的享受就是可以根据个人喜好去定制令自己舒服的系统配置,像终端颜色的设置就是一个典型的例子. 图1 系统默认状态下的终端显示 在没有经过自定义配置的终端下工作久了,难免容易疲劳,因为所 ...
随机推荐
- replication_slot and PostgreSQL Replication
主库IP:192.168.230.128 备库IP:192.168.230.129 PostgreSQL版本: 主备机PostgreSQL源码包均位于/opt/soft_bak OS:CentOS5 ...
- Leetcode: Lexicographical Numbers
Given an integer n, return 1 - n in lexicographical order. For example, given 13, return: [1,10,11,1 ...
- RelativeLayout相对布局属性
RelativeLayout用到的一些重要的属性: 第一类:属性值为true或falseandroid:layout_centerHrizontal 水平居中android:layout_center ...
- PAT乙级 1029. 旧键盘(20)
1029. 旧键盘(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 旧键盘上坏了几个键,于是在敲一段文字的 ...
- [ubuntu] ubuntu13.04安装rabbitcvs管理svn
加入源 sudo add-apt-repository ppa:rabbitvcs/ppa 更新 sudo apt-get update 安装软件 sudo apt-get install rabbi ...
- [python] No module named _sysconfigdata_nd
when setting python environment in Ubuntu13.04, i got this error: ImportError: No module named _sysc ...
- ubuntu sublime-text package control
1.ubuntu 环境下sublime-text的 package control一直配置失败 因为我下的是sublime-text3,而网上一般都是sublime-text2的教程. 2.subli ...
- 分数的加减法——C语言初学者代码中的常见错误与瑕疵(12)
前文链接:分数的加减法——C语言初学者代码中的常见错误与瑕疵(11) 重构 题目的修正 我抛弃了原题中“其中a, b, c, d是一个0-9的整数”这样的前提条件,因为这种限制毫无必要.只假设a, b ...
- OpenStack 的windows镜像的开启办法
创建虚拟机 使用我们的管理平台的windows主机创建流程,创建一台主机.在vnc中能看到主机进入到系统中 需要点击按钮sendctrl进入输入密码阶段. 输入我们的镜像的默认密码:5@mdjkw 打 ...
- iptables的四表五链
iptables只是Linux防火墙的管理工具而已,位于/sbin/iptables.真正实现防火墙功能的是netfilter,它是Linux内核中实现包过滤的内部结构. iptables包含4个表, ...