The Wayback Machine - https://web.archive.org/web/20241001115900/https://www.geeksforgeeks.org/visiting-card-scanner-gui-application-using-python/
Open In App

Visiting Card Scanner GUI Application using Python

Last Updated : 02 Nov, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Python is an emerging programming language that consists of many in-built modules and libraries. Which provides support to many web and agile applications. Due to its clean and concise syntax behavior, many gigantic and renowned organizations like Instagram, Netflix so-and-so forth are working in Python work-frame and heading towards magnificent growth. In this article, We are going to build GUI Application for scanning the Visiting card using Tkinter.

Tkinter is a very strong and user-friendly toolkit, as it provides users full control to modify its behavior and attributes of widgets available in the Tkinter library. Since Tkinter provides an object-oriented work-frame it is a far better way of programming for an application. The object-oriented interface in Tkinter satisfies the DRY (Do not repeat yourself) principle and helps to reduce redundancy of the code. 

Py-Libraries required:

Introduction of above-mentioned libraries:

  • Pytesseract library: Pytesseract is an ICR (Intelligent character recognition) and OCR (Optical character recognition) based toolkit available in python. It is a wrapper tool of Google and can “Extract” and “Read” the embedded text in any image. For getting started, Firstly, install and run Pytesseract on your system using the tesseract setup available here. To install pytesseract on the shell after installing the application from the above Github link
pip install pytesseract
  • Pillow library: It is a free open source library available in Python for image processing (manipulation, opening, and closing of various file formats i.e. jpeg/png).
pip install Pillow
  • Os module: It is an interactive module that deals with the transaction of files between the program and the operating system. os.path utility module provides the functionality of file sharing.

Program Approach:

  • Firstly, we will create an interface i.e. GUI using various widgets and attributes available in Tkinter like Label, Button, Frame, and so on.
  • After creating a basic layout we are now ready to make it responsive by implementing its main functionality i.e. uploading a file and then converting it.
  • File dialog box logic will work here so that properly formatted images can be uploaded to the software.
  • On successful upload, the system is now ready for conversion and now the Pytesseract module role comes into play. Pytesseract module will read and extract the embedded text from the image and will update the text area with that converted text.
  • Also, the File handling approach in python will create and append a text file with that converted text and will store it in our system’s local database.
  • The stored file can be accessed in the future for information and verification purposes.

Below is the full implementation:

Python3




# Visiting Card scanner GUI
 
# imported tkinter library
from tkinter import *
import tkinter.messagebox as tmsg   
 
# Pillow library for importing images
from PIL import Image, ImageTk
 
# library for filedialog (For file selection)
from tkinter import filedialog
 
# Pytesseract module importing
import pytesseract       
import os.path
 
root = Tk()
 
# fixing geometry of GUI
root.geometry('800x500')       
root.maxsize(1000, 500)
root.minsize(600, 500)
root.title('Visiting card scanner')
 
# function for uploading file to GUI
def upload_file():       
    global filename
    global start, last
    filename = filedialog.askopenfilename(
        initialdir='/Desktop', title = 'Select a card image',
      filetypes=(('jpeg files', '*.jpg'), ('png files', '*.png')))
     
    if filename == '':
        t.delete(1.0, END)
        t.insert(1.0, 'You have not provided any image to convert')
        tmsg.showwarning(
            title = 'Alert!', message = 'Please provide proper formatted image')
        return
       
    else:
        p_label_var.set('Image uploaded successfully')
        l.config(fg='#0CDD19')
     
    if filename.endswith('.JPG') or filename.endswith('.JPEG') or filename.endswith('.jpg') or filename.endswith('.jpeg') or filename.endswith('.PNG') or filename.endswith('.png'):
        filename_rev = filename[::-1]
        last = filename.index('.')
        start = len(filename) - filename_rev.index('/') - 1
 
# function for conversion
def convert():       
    try:
        c_label_var.set('Output...')
        pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract'
        text = pytesseract.image_to_string(filename)
        t.delete(1.0, END)
        t.insert(1.0, text)
        root1 = Toplevel()
        root1.title('Uploaded image')
        img1 = ImageTk.PhotoImage(Image.open(filename))
        Label(root1, image=img1).pack()
        root1.mainloop()
    except:
        t.delete(1.0, END)
        t.insert(1.0, 'You have not provided any image to convert')
        tmsg.showwarning(
            title='Alert!', message='Please provide proper formatted image')
        return
    f_name = filename[start+1:last]+'.txt'
    f_name = os.path.join(r'Database', f_name)
    f = open(f_name, 'w')
    f.write(text)
    f.close()
 
# Menu bar and navigation tab creation
mainmenu = Menu(root)
mainmenu.config(font = ('Times', 29))
 
m1 = Menu(mainmenu, tearoff = 0)
m1.add_command(label = 'Scan/Upload Visiting or Business cards and get all the text of cards',
               font = ('Times', 13))
root.config(menu = mainmenu)
mainmenu.add_cascade(label = 'Aim', menu = m1)
 
m2 = Menu(mainmenu, tearoff = 0)
m2.add_command(label = '|| Electronics and Communication engineering student ||',
               font = ('Times', 13))
m2.add_command(label = '|| Coding Enthusiast ||', font = ('Times', 13))
root.config(menu = mainmenu)
mainmenu.add_cascade(label = 'About us', menu = m2)
 
m3 = Menu(mainmenu, tearoff=0)
m3.add_command(label = 'E-mail: mathurkartik1234@gmail.com',
               font = ('Times', 13))
m3.add_separator()
m3.add_command(label = 'Mobile: +91-9587823004', font=('Times', 13))
m3.add_separator()
m3.add_command(label = 'LinkedIn: https://www.linkedin.com/in/kartik-mathur-97a825160',
               font = ('Times', 13))
root.config(menu = mainmenu)
mainmenu.add_cascade(label = 'Contact us', menu = m3)
 
Label(text = 'Visiting card scanner', bg = '#FAD2B8',
      fg = '#39322D', font = ('Times', 18)).pack(fill = 'x')
Label(text = 'Python GUI', bg = '#FAD2B8', fg ='#39322D', font=(
    'Times New Roman', 12, 'italic')).pack(fill='x')
 
f1 = Frame()
f1.config(bg='white')
Label(f1, text='Browse photo to upload', width=20,
      font=('Times', 15), bg='white').pack(side='left')
Label(f1, text='format: png/jpeg', bg='white',
      width=30).pack(side='right', padx=5)
Button(f1, text='Upload card', bg='#F58D4B', font=('Times', 15),
       width=70, command=upload_file).pack(side='right')
f1.pack(pady=10, fill='x')
p_label_var = StringVar()
p_label_var.set('Please upload an image to scan')
l = Label(textvariable=p_label_var, fg='red', bg='white')
l.pack()
 
Label(text='©copyright 2020', bg='#433E3B', fg='white',
      font=('Times', 10)).pack(side='bottom', fill='x')
Label(text='Developer: Kartik Mathur', bg='#433E3B', fg='white',
      font=('Times', 10, ' italic')).pack(side='bottom', fill='x')
t = Text(root, height='9', font=('Times', 13))
t.pack(side='bottom', fill='x')
t.insert(1.0, 'Text of converted card will be shown here...', END)
c_label_var = StringVar()
c_label_var.set('Ready for conversion')
c_label = Label(textvariable=c_label_var)
c_label.pack(side='bottom', anchor='w')
Button(root, text='Scan and Convert', bg='#F58D4B', font=('Times', 15),
       width=70, command=convert).pack(pady='10', side='bottom')
root.mainloop()


Output:

Visiting Card Scanner GUI

The above image depicts the application interface.

How to use and How it works?

  • User can scan and upload an image in two formats (i.e. jpeg, png)
  • On clicking “Upload Card” the user will land on the file dialog box and can select a required image to convert.
  • After a successful upload message will be prompted that image uploaded successfully.
  • Now user can convert it by clicking on the button “Scan and Convert”.
  • Text information will be shown in the text area and the converted file will be stored in the internal database.

Result and Analysis:

Accuracy and efficiency of conversion are very high, so it is recommended the use of this pytesseract library is a very efficient way of conversion.

Uploaded image

Image embedded text-to-plain text output



Previous Article
Next Article

Similar Reads

GUI Billing System and Menu Card Using Python
So imagine that we're starting a new restaurant or being appointed as one of the employees in a restaurant company, and we find out that there's no fast method of doing the billing of customers, and it usually takes times for us to calculate the amount that a customer has to pay. This can be really annoying and time taking thing for us as well as f
7 min read
Python | ToDo GUI Application using Tkinter
Prerequisites : Introduction to tkinter Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. In this article, we will learn how to create a ToDo GUI application using Tkinter, with a step-by-step guide. To create a tkinter : Importing the module – tkinter
5 min read
GUI chat application using Tkinter in Python
Chatbots are computer program that allows user to interact using input methods. The Application of chatbots is to interact with customers in big enterprises or companies and resolve their queries. Chatbots are mainly built for answering standard FAQs. The benefit of this type of system is that customer is no longer required to follow the same tradi
7 min read
Login Application and Validating info using Kivy GUI and Pandas in Python
Prerequisites : Kivy, Pandas Kivy is a multiplatform GUI library, known for being responsive. It provides management of multiple screens in a single application. In this application we will be using multiple screens to log in user's info and validate it. We will save the information in a csv file and use pandas to validate the information inside of
5 min read
Build a GUI Application to Get Live Stock Price using Python
The stock price is the highest amount someone is willing to pay for the stock. In this article, we are going to write code for getting live share prices for each company and bind it with GUI Application. Module Needed Yahoo_fin: This module is used to scrape historical stock price data, as well as to provide current information on market caps, divi
3 min read
Build a GUI Application to get distance between two places using Python
Prerequisite: Tkinter In this article, we are going to write a python script to get the distance between two places and bind it with the GUI application. To install the GeoPy module, run the following command in your terminal. pip install geopy Approach used: Import the geopy module.Initialize Nominatim API to get location from the input string.Get
2 min read
GUI Application for Live Cricket scoreboard Using Python
In this article, we will see how sports.py module is imported and implemented to produce scoreboard of a specified sport like baseball, basketball, cricket and many more along with other details about the sport. Code examples in the text below revolve around cricket, you can perform the same operation for any other sport. Sport.py Scrapes data from
3 min read
GUI application to search a country name from a given state or city name using Python
In these articles, we are going to write python scripts to search a country from a given state or city name and bind it with the GUI application. We will be using the GeoPy module. GeoPy modules make it easier to locate the coordinates of addresses, cities, countries, landmarks, and Zipcode. Before starting we need to install the GeoPy module, so l
2 min read
Build an GUI Application to Get Live Air Quality Information Using Python.
We are living in a modernization and industrialization era. Our life becomes more and more convenient. But the problem is Air Pollution arise with time. This Pollution makes us unhealthy, Air is a Lifeline for our life. In this article, we are going to write python scripts to get live air quality information and bind it with GUI Application. Module
5 min read
Build a GUI Application to ping the host using Python
Prerequisite: Python GUI – Tkinter In this article, we are going to see how to ping the host with a URL or IP using the python ping module in Python. This module provides a simple way to ping in python. And It checks the host is available or not and measures how long the response takes. “Before” starting we need to install this module into your sys
2 min read
Build GUI Application for Guess Indian State using Tkinter Python
In this article, you will learn to make a GUI game in Python, in which we will be shown a map of Indian states and an input prompt were in the prompt, the user has to enter a state name of India. If the user guessed it correctly, the name would hover over its location on the map. You can also see the score as the title of the input prompt window. M
8 min read
Create First GUI Application using Python-Tkinter
We are now stepping into making applications with graphical elements, we will learn how to make cool apps and focus more on its GUI(Graphical User Interface) using Tkinter. What is Tkinter?Tkinter is a Python Package for creating GUI applications. Python has a lot of GUI frameworks, but Tkinter is the only framework that’s built into the Python sta
12 min read
Hierarchical treeview in Python GUI application
Python uses different GUI applications that are helpful for the users while interacting with the applications they are using. There are basically three GUI(s) that python uses namely Tkinter, wxPython, and PyQt. All of these can operate with windows, Linux, and mac-OS. However, these GUI applications have many widgets i.e, controls that are helpful
3 min read
Build GUI Application Pencil Sketch from Photo in Python
In this article, we will cover how to convert images to watercolor sketches and pencil sketch Linux. Sketching and painting are used by artists of many disciplines to preserve ideas, recollections, and thoughts. Experiencing art from painting and sculpting to visiting an art museum—provides a variety of well-being advantages, including reduced stre
5 min read
Love Calculator GUI Application in Python
In this article, we are going to know how to make a GUI love calculator application using python. Prerequisite: Tkinter application, Python Random function. There are multiple ways in python to build a GUI(Graphical User Interface). Among all of those, the most commonly used one is Tkinter. It's the fastest and easiest way to make GUI applications
5 min read
PyQt5 - GUI Application to get IP address
In this article we will see how to make a simple PyQt5 application to get the IP address IP Address : An Internet Protocol address is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. An IP address serves two main functions: host or network interface identification and locat
3 min read
Port Scanner using Python
Prerequisites: Socket Programming in Python This article is just to provide a sample code to generate a Port Scanner. This Port Scanner will work for both the Web Applications as well as remote Host. This tool has been created to provide the basic functionality of a Port Scanner. The general concept of Sockets had been used to provide the functiona
2 min read
Simple Port Scanner using Sockets in Python
Prerequisites: Socket Programming in Python Before going to the programming, let us discuss about ports. In this article, we will check the virtual ports of a server or websites, or localhost. Every port has a unique number. There are 65,535 ports available in a host starting from 0. We can assign the ports for any services. Example 1: In this prog
3 min read
Threaded Port Scanner using Sockets in Python
Port scanning can be really slow yet, in most cases, is not process intensive. Thus, we can use threading to improve our speed. There can be thousands of possible ports. If it takes 5-15 seconds per port to scan, then we might have a long wait ahead of us without the use of threading. Threading Threading is a complex topic, but it can be broken dow
2 min read
How to Build a WiFi Scanner in Python using Scapy?
In this article, we are going to build a WiFi Scanner in Python using Scapy. WiFi Scanning or Network scanning refers to the scanning of the whole network to which we are connected and try to find out what are all the clients connected to our network. We can identify each client using their IP and MAC address. We can use ARP ping to find out the al
3 min read
Build an Application to Search Installed Application using Python
In this article, we are going to write python scripts to search for an installed application on Windows and bind it with the GUI application. We are using winapps modules for managing installed applications on Windows. Prerequisite - Tkinter in Python To install the module, run this command in your terminal: pip install winapps Below is what the GU
6 min read
Webcam QR code scanner using OpenCV
In this article, we're going to see how to perform QR code scanning using a webcam. Before starting, You need to know how this process is going to work. Firstly you need to open your webcam, and you've to run your python program to make it ready to scan the QR code. You can take the Qr code picture on your mobile and show the picture in front of yo
3 min read
Python - Simple Port Scanner with Sockets
Ports can be scanned to check which ports are engaged and which ports are open or free. In Python "Socket" module provides access to the BSD socket interface, which is available on all platforms. To scan the ports, the following steps can be implemented: 1] Recognize the host's IP address 2] Create new socket 3] Forming a connection with port 4] Ch
2 min read
How to Build a SQL Injection Scanner in Python?
In general terms, SQLi is the most prevalent and dangerous code insertion technique. An SQLi attack is meant to send malicious SQL commands to the database server. The most common attack goal is bulk extraction of knowledge. Attackers can dump database tables with many thousands of customer records. Depending on the environment, SQL injection also
3 min read
How to Make a Subdomain Scanner in Python?
In this article, we are going to scan the subdomains using requests module in Python, which allows us to easily make HTTPS requests to get information from the websites. To install the requests module, write the following command in your command prompt. pip install requests The URL (Uniform Resource Locator) consists mainly of four parts: ProtocolS
6 min read
Network Scanner in Python
A network scanner is one major tool for analyzing the hosts that are available on the network. A network scanner is an IP scanner that is used for scanning the networks that are connected to several computers. To get the list of the available hosts on a network, there are two basic methods - ICMP Echo Request It is also known by using ‘ping command
3 min read
Using lambda in GUI programs in Python
Python Lambda Functions are anonymous function means that the function is without a name. In this article, we will learn to use lambda functions in Tkinter GUI. We use lambda functions to write our code more efficiently and to use one function many times by passing different arguments. We use the lambda function to pass arguments to other functions
3 min read
Python | Simple GUI calculator using Tkinter
Prerequisite: Tkinter Introduction, lambda function Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and easiest way to create GUI a
6 min read
Python | Distance-time GUI calculator using Tkinter
Prerequisites : Introduction to Tkinter | Using google distance matrix API Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest wa
7 min read
Cryptography GUI using python
Using cryptography techniques we can generate keys for a plain text which can not be predicted easily. We use Cryptography to ensure the safe and secure flow of data from one source to another without being accessed by a malicious user. Prerequisites: Language used - Python. Tkinter - This module is used to make GUIs using python language. To know
4 min read