Skip to content
← Back to Community
How do you change the font in Python?
Profile icon
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
Profile icon
rpearce04
Profile icon
ShrinivasDornal
Profile icon
k9chelsea2
Profile icon
gibbsfreenergy
Comments
hotnewtop
Profile icon
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.

Profile icon
gibbsfreenergy

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

Profile icon
adl212

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

Profile icon
gibbsfreenergy

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

Profile icon
adl212

@JosephSanthosh The ANSI color codes are

BLACK = "\033[0;30m" RED = "\033[0;31m" GREEN = "\033[0;32m" BROWN = "\033[0;33m" BLUE = "\033[0;34m" PURPLE = "\033[0;35m" CYAN = "\033[0;36m" LIGHT_GRAY = "\033[0;37m" DARK_GRAY = "\033[1;30m" LIGHT_RED = "\033[1;31m" LIGHT_GREEN = "\033[1;32m" YELLOW = "\033[1;33m" LIGHT_BLUE = "\033[1;34m" LIGHT_PURPLE = "\033[1;35m" LIGHT_CYAN = "\033[1;36m" LIGHT_WHITE = "\033[1;37m" BOLD = "\033[1m" FAINT = "\033[2m" ITALIC = "\033[3m" UNDERLINE = "\033[4m" BLINK = "\033[5m" NEGATIVE = "\033[7m" CROSSED = "\033[9m" END = "\033[0m"

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

Profile icon
gibbsfreenergy

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

Profile icon
adl212

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

Profile icon
gibbsfreenergy

never mind I found out. [email protected]

Profile icon
Coder100

there's more... @adl212

Profile icon
adl212

@Coder100 Ok, go ahead and tell us!

Profile icon
Coder100

alright, there's also rgb support:

\033[38;2;⟨r⟩;⟨g⟩;⟨b⟩m

and 8bit (256 colors):

\033[38;5;⟨n⟩m

@adl212

Profile icon
gibbsfreenergy

there are 256 [email protected]

Profile icon
adl212

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

Profile icon
Coder100

:) glad to introduce ya @adl212

Profile icon
gibbsfreenergy
Profile icon
Coder100
Profile icon
adl212

@JosephSanthosh No problem!

Profile icon
Coder100

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

print('\033[1mBold text\033[0m normal text')

Using ANSI escape codes. Wikipedia docs

Hopes this helps!

Profile icon
gibbsfreenergy

What does that code do? @Coder100

Profile icon
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

Profile icon
gibbsfreenergy

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

Profile icon
Coder100

and is the bold text bold? @JosephSanthosh

Profile icon
gibbsfreenergy
Profile icon
Coder100
Profile icon
wesleyBoi

I can't seem to get the blink to work:
user = input("\033[5m" + 'Create a username:' + "\033[0m")

Profile icon
HahaYes

can't you use matplotlib for python?