鱼C论坛

 找回密码
 立即注册
查看: 2360|回复: 3

[已解决]请问print()怎么输出带颜色的字符

[复制链接]
发表于 2016-12-27 21:13:47 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
如题,貌似没见到设置屏幕颜色参数的句子啊,看文档看了半天,有个color语句,但是用了之后弹出了一个界面,不是打印界面,好像没什么意义来着,还有网上有一些设置颜色参数的教程,但是根本没用,呵呵
请教小伙伴们怎么设置你的打印输出颜色
最佳答案
2016-12-28 11:08:58
按照楼上帖子里的方法,在Ipython中可行:
  1. def print_format_table():
  2.     """
  3.     prints table of formatted text format options
  4.     """
  5.     for style in range(8):
  6.         for fg in range(30,38):
  7.             s1 = ''
  8.             for bg in range(40,48):
  9.                 format = ';'.join([str(style), str(fg), str(bg)])
  10.                 s1 += '\x1b[%sm %s \x1b[0m' % (format, format)
  11.             print(s1)
  12.         print('\n')

  13. print_format_table()
复制代码

无标题.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-12-28 10:08:19 | 显示全部楼层
For Windows you cannot print to console with colors unless you're using the win32api.

http://stackoverflow.com/questio ... colors-using-python
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-12-28 11:08:58 | 显示全部楼层    本楼为最佳答案   
按照楼上帖子里的方法,在Ipython中可行:
  1. def print_format_table():
  2.     """
  3.     prints table of formatted text format options
  4.     """
  5.     for style in range(8):
  6.         for fg in range(30,38):
  7.             s1 = ''
  8.             for bg in range(40,48):
  9.                 format = ';'.join([str(style), str(fg), str(bg)])
  10.                 s1 += '\x1b[%sm %s \x1b[0m' % (format, format)
  11.             print(s1)
  12.         print('\n')

  13. print_format_table()
复制代码

无标题.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-12-29 01:33:53 | 显示全部楼层
牛逼了你们!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-18 19:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表