The Wayback Machine - https://web.archive.org/web/20240926194803/https://www.geeksforgeeks.org/print-font-using-python/
Open In App

Print with your own font using Python !!

Last Updated : 22 Aug, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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
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
Implement your own word2vec(skip-gram) model in Python
Natural 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 types of language modeling techniques
9 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
Change your way to put logic in your code - Python
Aren't you bored coding in the same traditional logic over these years. It's time to bring some differences. Well, be it any programming language. When we are asked to do some sort of basic programming exercises like sorting, searching, prime number checking, etc. we are all driven towards the same boat, which is the same coding logic. Now, we are
5 min read
Don't Let Your Geographical Location Be A Barrier In Your Success - Live Classes By GeeksforGeeks
Winter is coming and so is the placement season! And there are many companies that recruit during this time including product-based companies, startups or service-based companies. So if you want to succeed and bag your dream job, thorough interview preparation is a must!!! Now I am sure interviews scare you a lot, just like most candidates!!! But y
6 min read
Python PyQt5 – How to change font and size of Status Bar Message
We can set message to a Status Bar by using showMessage() method. In this article, we will see how to change the font and the size of StatusBar message. In order to do this we will use setFont() method. Syntax : self.statusBar().setFont(QFont(font_name, font_size)) Argument : It take two argument : 1. Font name it can be ‘Arial’, ’Times’ etc. 2. Si
1 min read
Set Pandas dataframe background Color and font color in Python
As we know, the basic idea behind styling is to make more impactful for the end-user readability. We can make changes like the color and format of the data visualized in order to communicate insight more efficiently. For the more impactful visualization on the pandas DataFrame, generally, we DataFrame.style property, which returns styler object hav
3 min read
How to Change the Font Size in Python Shell?
In this article, we will see how to Change the Font Size in Python Shell Follow these steps to change font size: Step 1: Open the Python shell Step 2: Click on the Options and select Configure IDLE Step 3: In Fonts/Tabs tab set Size value Step 4: Let's select a size value is 16 and click on Apply and click on Ok Step 5: Now Font size is increase to
1 min read
How to manually add a legend color and legend font size on a plotly figure in Python?
In this article, we will learn how to manually add a legend color and legend font size on a plotly figure in Python. A legend is an area describing the elements of the graph. In the plotly legend is used to Place a legend on the axes. Here we will discuss different methods for manually adding legend color and legend font size in plotly express, usi
2 min read
PyQt5 – How to change font and size of Label text ?
A label is a graphical control element which displays text on a form. A label is generally used to identify a nearby text box or other widget. Some labels can respond to events such as mouse clicks, allowing the text of the label to be copied, but this is not standard user-interface practice. In this article, we will see how to change the font and
2 min read
PyQt5 – Change the text font and size in Push button
In this article we will see how to change the text style or size of Push Button.QPushButton is a simple button in PyQt, when clicked by a user some associated action gets performed. For adding this button into the application, QPushButton class is used.In order to set font we will use setFont method which takes QFont object as argument. Syntax : bu
2 min read
PyQt5 - Font and size of content in Radio button
In this article we will see how we can set font and the size to the content of radio button, there are basically two parts of radio button one is the indicator part and the other one is the label part which contain the content. In order to change the font and the size of content we have to change the style sheet code of radio button, below is the s
2 min read
PyQt5 - Setting font to all the items in ComboBox
In this article we will see how we can change the size and font of all the items present in the list. In order to do so we will use setFont method which takes QFont object as argument, using it with the check box object will change the font of all the items present in the list. Syntax : check_box.setFont(font) Argument : It takes Font object as arg
2 min read
PyQt5 - Setting font to the item in line edit box of ComboBox
In this article we will see how we can change the size and font of the item present in the editable. If we use setFont method which takes QFont object as argument, using it with the check box object will change the font of all the items present in the list. In order to change the font and size of only the item which is in the editable box, do the f
2 min read
PyQt5 – Setting font to line editbox item of non-editable ComboBox
In this article we will see how to change the size and font of the item present in the editable box. If we use setFont method which takes QFont object as argument, using it with the check box object will change the font of all the items present in the list. Note : When we get the line edit object from the combo box it will make the combo box there
2 min read
PyQt5 QSpinBox - Setting font to the whole text
In this article we will see how we can change the size and font of all the text present in the spin box, in order to do so we will use setFont method which takes QFont object as argument, using it with the spin box object will change the font of all the text. Syntax : spin_box.setFont(font) Argument : It takes QFont object as argument Return : It r
2 min read
PyQt5 QSpinBox - How to get the font of spin box
In this article we will see how we can get the font of all the text present in the spin box, in order to set the font use setFont method which takes QFont object as argument, using it with the spin box object will change the font of all the text. In order to get the font we use font method Syntax : spin_box.font() Argument : It takes no argument Re
2 min read
PyQt5 QSpinBox - Getting Font Info Object
In this article we will see how we can get the font info object of the spin box, in order to set the font use setFont method which takes QFont object as argument, using it with the spin box object will change the font of all the text. Font Info object is an object which tells about the properties of the text like it is bold or not etc. In order to
2 min read
PyQt5 QSpinBox - Swapping Font
In this article we will see how we can swap the fonts of the spin box, swapping font of spin box means to replace the QFont object of spin box with other QFont object. We can get the QFont object of spin box with the help of font method. In order to do this we use swap method with the QFont object of the spin box Syntax : font.swap(another_font) Ar
2 min read
PyQt5 QSpinBox - How to get the font metrics
In this article we will see how we can get the font metrics of the spin box. The QFontMetrics class provides font metrics information, it calculate the size of characters and strings for a given font. It basically consist of the positioning details of the spin box font. In order to do this we use fontMetrics method with the spin box object. Syntax
2 min read
PyQt5 QSpinBox - Getting ascent of the font
In this article we will see how we can get the ascent of the spin box's font i.e text. The ascent of a font is the distance from the baseline to the highest position characters extend to. In practice, some font designers break this rule, e.g. when they put more than one accent on top of a character, or to accommodate an unusual character in an exot
2 min read
PyQt5 QSpinBox - Getting descent of the font
In this article we will see how we can get the descent of the spin box's font i.e text. The descent is the distance from the base line to the lowest point characters extend to. In practice, some font designers break this rule, e.g. to accommodate an unusual character in an exotic language, so it is possible (though rare) that this value will be too
2 min read
PyQt5 QSpinBox - How to get the elided text through font
In this article we will see how we can get the elided text of the spin box. If the string text is wider than width, an elided version of the string would be a string with "..." in it. Otherwise, original string will be displayed. There are three mode parameters to get the elided text. The mode parameter specifies whether the text is elided on the l
2 min read