Open In App

Print with your own font using Python !!

Last Updated : 22 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Programming’s core function is printing text, but have you ever wished to give it a unique look by utilizing your own custom fonts? Python enables you to use imagination and overcome the standard fonts in your text outputs. In this article, we will do some cool Python tricks. For the user input, the given code will print in the designed font.

Example: 

Input: ROOT
Output:
..######..
..#....#..
..#.##...                    
..#...#...
..#....#..
..######..
..#....#..
..#....#..                    
..#....#..
..######..
..######..
..#....#..
..#....#..                    
..#....#..
..######..
..######..
....##....
....##....                    
....##....
....##....

Explanation: In this, we are printing our own font using Python.

Print with your own font using Python  

Here we are printing our own font using Python. Below is Python3 code implementation :

Python3




# Python3 code to print input in your own font
name = "GEEK"
 
# To take input from User
# name = input("Enter your name: \n\n")
 
length = len(name)
l = ""
 
for x in range(0, length):
    c = name[x]
    c = c.upper()
     
    if (c == "A"):
        print("..######..\n..#....#..\n..######..", end = " ")
        print("\n..#....#..\n..#....#..\n\n")
         
    elif (c == "B"):
        print("..######..\n..#....#..\n..#####...", end = " ")
        print("\n..#....#..\n..######..\n\n")
         
    elif (c == "C"):
        print("..######..\n..#.......\n..#.......", end = " ")
        print("\n..#.......\n..######..\n\n")
         
    elif (c == "D"):
        print("..#####...\n..#....#..\n..#....#..", end = " ")
        print("\n..#....#..\n..#####...\n\n")
         
    elif (c == "E"):
        print("..######..\n..#.......\n..#####...", end = " ")
        print("\n..#.......\n..######..\n\n")
         
    elif (c == "F"):
        print("..######..\n..#.......\n..#####...", end = " ")
        print("\n..#.......\n..#.......\n\n")
         
    elif (c == "G"):
        print("..######..\n..#.......\n..#.####..", end = " ")
        print("\n..#....#..\n..#####...\n\n")
         
    elif (c == "H"):
        print("..#....#..\n..#....#..\n..######..", end = " ")
        print("\n..#....#..\n..#....#..\n\n")
         
    elif (c == "I"):
        print("..######..\n....##....\n....##....", end = " ")
        print("\n....##....\n..######..\n\n")
         
    elif (c == "J"):
        print("..######..\n....##....\n....##....", end = " ")
        print("\n..#.##....\n..####....\n\n")
         
    elif (c == "K"):
        print("..#...#...\n..#..#....\n..##......", end = " ")
        print("\n..#..#....\n..#...#...\n\n")
         
    elif (c == "L"):
        print("..#.......\n..#.......\n..#.......", end = " ")
        print("\n..#.......\n..######..\n\n")
         
    elif (c == "M"):
        print("..#....#..\n..##..##..\n..#.##.#..", end = " ")
        print("\n..#....#..\n..#....#..\n\n")
         
    elif (c == "N"):
        print("..#....#..\n..##...#..\n..#.#..#..", end = " ")
        print("\n..#..#.#..\n..#...##..\n\n")
         
    elif (c == "O"):
        print("..######..\n..#....#..\n..#....#..", end = " ")
        print("\n..#....#..\n..######..\n\n")
         
    elif (c == "P"):
        print("..######..\n..#....#..\n..######..", end = " ")
        print("\n..#.......\n..#.......\n\n")
         
    elif (c == "Q"):
        print("..######..\n..#....#..\n..#.#..#..", end = " ")
        print("\n..#..#.#..\n..######..\n\n")
         
    elif (c == "R"):
        print("..######..\n..#....#..\n..#.##...", end = " ")
        print("\n..#...#...\n..#....#..\n\n")
         
    elif (c == "S"):
        print("..######..\n..#.......\n..######..", end = " ")
        print("\n.......#..\n..######..\n\n")
         
    elif (c == "T"):
        print("..######..\n....##....\n....##....", end = " ")
        print("\n....##....\n....##....\n\n")
         
    elif (c == "U"):
        print("..#....#..\n..#....#..\n..#....#..", end = " ")
        print("\n..#....#..\n..######..\n\n")
         
    elif (c == "V"):
        print("..#....#..\n..#....#..\n..#....#..", end = " ")
        print("\n...#..#...\n....##....\n\n")
         
    elif (c == "W"):
        print("..#....#..\n..#....#..\n..#.##.#..", end = " ")
        print("\n..##..##..\n..#....#..\n\n")
         
    elif (c == "X"):
        print("..#....#..\n...#..#...\n....##....", end = " ")
        print("\n...#..#...\n..#....#..\n\n")
         
    elif (c == "Y"):
        print("..#....#..\n...#..#...\n....##....", end = " ")
        print("\n....##....\n....##....\n\n")
         
    elif (c == "Z"):
        print("..######..\n......#...\n.....#....", end = " ")
        print("\n....#.....\n..######..\n\n")
         
    elif (c == " "):
        print("..........\n..........\n..........", end = " ")
        print("\n..........\n\n")
         
    elif (c == "."):
        print("----..----\n\n")


Output: 

..######..
..#.......
..#.####..
..#....#..
..#####...
..######..
..#.......
..#####...
..#.......
..######..
..######..
..#.......
..#####...
..#.......
..######..
..#...#...
..#..#....
..##......
..#..#....
..#...#...

Time complexity of this code is O(n^2) where n is the length of the input string name. 

The auxiliary space complexity of this code is O(1).

Print with your own font using Python using Dictionary Mapping

Here we will print text using a custom font created using ASCII art representations. This can be done by using a dictionary mapping to associate each uppercase character with its corresponding ASCII art representation.

Python3




ascii_art = {
    "A": "..######..\n..#....#..\n..######..",
    "B": "..######..\n..#....#..\n..#####...",
    "C": "..######..\n..#.......\n..#.......",
    "D": "..######..\n..#.......\n..#.......",
    "E": "..#####...\n..#....#..\n..#....#..",
    "F": "..######..\n..#.......\n..#####...",
    "G": "..######..\n..#.......\n..#.####..",
    "H": "..#....#..\n..#....#..\n..######..",
   
    # Add more characters...
}
 
# Input name for which you want to print ASCII art
name = "GEEK"
 
# Iterate through each character in the name
for char in name:
    # Convert the character to uppercase
    char_upper = char.upper()
     
    # Check if the uppercase character exists in the ASCII art dictionary
    if char_upper in ascii_art:
        # Print the ASCII art representation of the character
        print(ascii_art[char_upper], end=" ")
    else:
        # If the character is not found in the dictionary, print a message
        print("Character not found in ASCII art dictionary")


Output:

..######..
..#.......
..#.####.. ..#####...
..#....#..
..#....#.. ..#####...
..#....#..
..#....#.. Character not found in ASCII art dictionary

Print with your own font using Python using Functions

Here we will print text using a custom font created using ASCII art representations. This can be done by using Functions.

Python3




def print_char(char):
    char_upper = char.upper()
    if char_upper == "A":
        print("..######..\n..#....#..\n..######..", end=" ")
          
    elif char_upper == "B":
        print("..######..\n..#....#..\n..#####...", end=" ")
         
    elif char_upper == "C":
        print("..######..\n..#.......\n..#.......", end = " ")
         
         
    elif char_upper == "D":
        print("..#####...\n..#....#..\n..#....#..", end = " ")
         
         
    elif char_upper == "E":
        print("..######..\n..#.......\n..#####...", end = " ")
        
         
    elif char_upper == "F":
        print("..######..\n..#.......\n..#####...", end = " ")
         
    elif char_upper == "G":
        print("..######..\n..#.......\n..#.####..", end = " ")
         
         
    elif char_upper == "H":
        print("..#....#..\n..#....#..\n..######..", end = " ")
         
    # Add more characters...
 
name = "GEEK"
 
for char in name:
    print_char(char)
    print()  # Print a newline after each character's ASCII art


Output:

..######..
..#.......
..#.####.. 
..######..
..#.......
..#####... 
..######..
..#.......
..#####... 



Previous Article
Next Article

Similar Reads

How to create your own Avatar using Python ?
In this article, we will discuss how to create a custom avatar using Python. In order to perform this task. You don't have to create it yourself on software or download it from some website, but a few lines of code will help you to generate an avatar of your choice. We will be using the py-avataaars package from which we will be creating those beau
3 min read
Build Your Own Voice-Activated Calculator Using Python
In this article, you'll be delving into the development of a voice command calculator using Python, taking advantage of libraries like Speech-Recognition and PyAudio that will allow users with swift means of performing arithmetic operations. Developing such a program will require you to go through some of the basics of speech recognition and PyAudi
6 min read
Creating Your Own Python IDE in Python
In this article, we are able to embark on an adventure to create your personal Python Integrated Development Environment (IDE) the usage of Python itself, with the assistance of the PyQt library. What is Python IDE?Python IDEs provide a characteristic-rich environment for coding, debugging, and going for walks in Python packages. While there are ma
3 min read
PyQt5 QSpinBox - Matching font with the System Font
In this article we will see how we can match the font of the spin box with the system font, Matching of font means it is similar to that of the system font. We can get the QFont object of spin box with the help of font method. Note : Make text italic or bold doesn't mean the font has changed, by default system has Arial font. If we set different fo
2 min read
Implement your own word2vec(skip-gram) model in Python
Prerequisite: Introduction to word2vecNatural language processing (NLP) is a subfield of computer science and artificial intelligence concerned with the interactions between computers and human (natural) languages. In NLP techniques, we map the words and phrases (from vocabulary or corpus) to vectors of numbers to make the processing easier. These
6 min read
Python Program To Write Your Own atoi()
The atoi() function in C takes a string (which represents an integer) as an argument and returns its value of type int. So basically the function is used to convert a string argument to an integer. Syntax: int atoi(const char strn) Parameters: The function accepts one parameter strn which refers to the string argument that is needed to be converted
4 min read
Write your own len() in Python
The method len() returns the number of elements in the list or length of the string depending upon the argument you are passing. How to implement without using len(): Approach: Take input and pass the string/list into a function which return its length.Initialize a count variable to 0, this count variable count character in the string.Run a loop ti
2 min read
Build Your Own Microservices in Flask
Nowadays Python is everywhere. This is majorly due to its simplicity and wide range of applications. Flask is a lightweight web framework for building web applications in Python. Creating microservices with Flask is straightforward. In this article, we will start with a basic "hello world" microservice. Following that, we'll delve into the creation
5 min read
Create your own universal function in NumPy
Universal functions in NumPy are simple mathematical functions. It is just a term that we gave to mathematical functions in the Numpy library. Numpy provides various universal functions that cover a wide variety of operations. However, we can create our universal function in Python. In this article, we will see how to create our own universal funct
2 min read
Program to print its own name as output
Ever thought about writing a script which prints its own name when you execute it. It's pretty simple. You must have noticed programs in which the main function is written like this int main(int argc, char** argv) and you must have wondered what these 2 arguments mean. Well the first one argc is the number of arguments passed in to your program.The
2 min read