CREATE AWESOME ASCII TEXT ART IN PYTHON, WITH ‘PYFIGLET’

Antonio Alfonso Martinez
4 min readMar 14, 2023

--

When we program a console application, we cannot carry out customizations of its appearance, as we can do when we work with graphical interfaces. However, we can give it a personal touch, resorting to resources such as the color of the text (what we can do with “colorama”, which we will talk about at another time) or the inclusion of “ascii” fonts for our presentations. For the latter we have a curious library called “pyfiglet” that will greatly facilitate our work.

To start working with this library, the first thing we must do (if we have not already done so) is installing it on our computer:

Once this is done, we are ready to start. We’ll start by displaying the message “hello world!” in the default font style:

To do this, we have used the “figlet_format()” method, to which in this case we have only passed the text to be represented as an argument. Showing this in the ‘standard’ source (the one that is established by default). However, we can choose another of the many available fonts and styles by adding a second “font” argument. This is how our text would look using the “speed” font:

As you can see, every time we use the “figlet_format()” method, our text will be left aligned by default. However, we can use a new “justify” argument to specify whether we want it left, centered, or right-aligned (as long as its length allows it):

A fourth argument that we can include is “width” with which we will specify the space that we are going to need for our example. So, let’s say we want to display “hello world” in a font called “isometric3”:

We see how, given both the type of font and the length of the text, it must be displayed in two lines. This is where the “width” value allows us to expand the space for our text, so that it can be displayed in its entirety on a single line:

Pyfiglet has a large number of fonts whose names we can access through the “getFonts()” method:

What will show on the screen the list with the names of all the sources that we can use:

A visual way to see all the fonts would be by running this line of code:

Finally, remember that we can use this library together with other tools such as “colorama” (which we have already talked about) to customize and give our console applications a more attractive touch:

And up to here this brief article in which we have seen how we can give a more personal and striking touch to our console applications through this curious and interesting library.

See you.

--

--