Ask coding questions

← Back to all posts
How do you change the font in Python?
gibbsfreenergy

How do you change the font in Python? Would be pretty cool to learn this.

Answered by adl212 [earned 5 cycles]
View Answer
Voters
ShrinivasDornal
k9chelsea2
gibbsfreenergy
Comments
hotnewtop
adl212

Unfortunately, you can not change the font family of text in python. But, you can change the color of the text or add markdown to the text. Hope this answers your question! Upvote or choose as the correct answer if so.

gibbsfreenergy

@adl212 thx, but is there any other way I can decorate the text even more besides colors?

adl212

@JosephSanthosh You can use bold, underline, and etc.

gibbsfreenergy

do u know what or where the codes are? @adl212

adl212

@JosephSanthosh The ANSI color codes are

Just add them to your print function and it will change the text!

gibbsfreenergy

how do i write it inside a print() [email protected]

adl212

@JosephSanthosh You would do something like print("\033[1m" + "This is bold text!" + "\033[0m")Hope this helps!

gibbsfreenergy

never mind I found out. [email protected]

Coder100

there's more... @adl212

adl212

@Coder100 Ok, go ahead and tell us!

Coder100

alright, there's also rgb support:

and 8bit (256 colors):

@adl212

gibbsfreenergy

there are 256 [email protected]

adl212

@Coder100 Ok, great! I didn't know of these!

Coder100

:) glad to introduce ya @adl212

gibbsfreenergy

thanks guys @Coder100 @adl212

Coder100
adl212

@JosephSanthosh No problem!

Coder100

You can't change the font, but you can change the colors.
Example:

Using ANSI escape codes. Wikipedia docs

Hopes this helps!

gibbsfreenergy

What does that code do? @Coder100

Coder100

so \033[ is the escape code and m just means the end of the escape code. The number in between is the special number that is desired. (look at the Wikipedia page to see all) @JosephSanthosh

gibbsfreenergy

but when I run it just shows 'Bold text normal text' @Coder100

Coder100

and is the bold text bold? @JosephSanthosh

gibbsfreenergy
Coder100
HahaYes

can't you use matplotlib for python?