w3resource

Python Projects: Print colored text, bold, italic, faint, blink, on terminal window

Python Project-6 with Solution

Create a Python project that will help to print colored text, bold, italic, faint, blink (slow/fast), on terminal window.

Sample Solution:

Python Code:

#Source:  https://bit.ly/2WBq9Jv
def ansi_color(n,s):
	code={"bold":1,"faint":2,"italic":3,"underline":4,"blink_slow":5,"blink_fast":6,"negative":7,"conceal":8,"strike_th":9,
	"black":30,"red":31,"green":32,"yellow":33,"blue":34,"magenda":35,"cyan":36,"white":37,
	"b_black":40,"b_red":41,"b_green":42,"b_yellow":43,"b_blue":44,"b_magenda":45,"b_cyan":46,"b_white":47,}
	try:
		num=str(code[n])
		value="\033["+num+"m"+s+"\033[0m"
		return value
	except:
		pass
def list_code():
	code={"bold":1,"faint":2,"italic":3,"underline":4,"blink_slow":5,"blink_fast":6,"negative":7,"conceal":8,"strike_th":9,
	"black":30,"red":31,"green":32,"yellow":33,"blue":34,"magenda":35,"cyan":36,"white":37,
	"b_black":40,"b_red":41,"b_green":42,"b_yellow":43,"b_blue":44,"b_magenda":45,"b_cyan":46,"b_white":47,}
	for i,j in code.items():
		print (str(j)+"\t"+i)

print (ansi_color('bold',"Python Project"))
print (ansi_color('faint',"Python Project"))
print (ansi_color('blink_slow',"Python Project"))
print (ansi_color('blink_fast',"Python Project"))


Output:

Python Project
Python Project

Python Project
Python Project

Flowchart:

Python Flowchart: Print colored text, bold, italic, faint, blink, on terminal window

Contribute your code and comments through Disqus.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/projects/python/python-projects-6.php