Python Spelling Checker & Corrector with Source Code

Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python

We all make spelling mistakes, what we call typos while writing messages, emails, etc. Writing this article, I even made multiple typos! And we take the help of assistants on our devices to help us out in these moments. Do you know you can build such a system to correct your spelling following some simple steps using Python? We will do the same in this Python Spell Correction Project. Let’s start!!!

What is a Spell Corrector?

Writing should always have no spelling errors to let the reader get the correct understanding. But being humans, it is common for all of us to make some errors. And that’s the reason the spell correctors are developed. These check the spelling of words and suggest the correct word if wrong. We will be building a prototype of a spelling corrector using Python.

Spell Checker using Python

To build this project, we will be using the Tkinter module and TextBlob modules from Python. We use the Tkinter module to build the GUI for taking input from the user and showing the output based on the spelling typed. And to do this check we will be using the TextBlob module.

Download Python Spell Checker & Corrector Project

Please download the source code for the python spell checker & corrector project from the following link: Python Spelling Checker & Corrector Project

Project Prerequisites

The prior knowledge of Python and the Tkinter module would be helpful while building this module. And to install the two modules we just talked about, the following commands would be of use.

pip install tkinter
pip install textblob

Steps to build the Spell Checker & Corrector Project in Python

Every project requires the developer to have a step-by-step flow to make the task simpler. And now we will be discussing the flow of this python project.

  1. First we import the Tkinter and the TextBlob modules
  2. Then we create the GUI and add the required widgets
  3. Finally, we write the function to check the spelling and give the corresponding output.

1. Importing the module

The first step is to import the modules tkinter and the TextBlob class from the textblob module.

#Importing modules
from textblob import TextBlob
from tkinter import *

2. Creating the GUI

Then we create an empty GUI for adding the widgets.

#Creating the window
wn = Tk()
wn.title("DataFlair Spell Checker")
wn.geometry('500x250')
wn.config(bg='SlateGray1')

3. Adding the required widgets

Now it’s time to add the widgets. We need

Technology is evolving rapidly!
Stay updated with DataFlair on WhatsApp!!

1. An Entry() to get the input of word from the user of which the spell check is to be done
2. A button to run the function that does the spell check
3. A Label() to show the corrected word

#Creating the variables to get the word and set the correct word
text=StringVar(wn)
correctedText =StringVar(wn)

#The main label
Label(wn, text='DataFlair Spell Checker',bg='SlateGray1',
fg='gray30', font=('Times', 20,'bold')).place(x=100, y=10)

#Getting the input of word from the user
Label(wn, text='Please enter the word',bg='SlateGray1',font=('calibre',13,'normal'), anchor="e", justify=LEFT).place(x=20, y=70)

Entry(wn,textvariable=text, width=35,font=('calibre',13,'normal')).place(x=20,y=110)

#Label to show the correct word
opLabel = Label(wn, textvariable=correctedText, bg='SlateGray1',anchor="e",font=('calibre',13,'normal'), justify=LEFT).place(x=20, y=130)

#Button to do the spell check
Button(wn, text="Click Me", bg='SlateGray4',font=('calibre', 13),
command=checkSpelling).place(x=230, y=190)

#Runs the window till it is closed by the user
wn.mainloop()

4. Writing the function to check the spelling show output

This function runs when the user clicks the button.

1. We first take the input word
2. Then we create an object for this word
3. Then we show the correct word in the label

#Function to check the spelling and show the corrected spelling
def checkSpelling():
 a = text.get() #Getting the word user entered
 b = TextBlob(a) #Getting the object for the word
 correctedText.set("The corrected word is: "+str(b.correct())) #Showing the corrected word

Python Spell Checker & Corrector Output

Image of the Spell Checker GUI

python spell checker corrector output

Summary

Hurray! You have successfully built the Spell Checker and correction project using the Tkinter and TextBlob Python modules. We learned to create GUI, add widgets and check spellings. Hope you enjoyed building with us!

Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

courses

DataFlair Team

DataFlair Team is a group of passionate educators and industry experts dedicated to providing high-quality online learning resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With years of experience in the field, the team aims to simplify complex topics and help learners advance their careers. At DataFlair, we believe in empowering students and professionals with the knowledge and skills needed to thrive in today’s fast-paced tech industry. Follow us for Free courses, expert insights, tutorials, and practical tips to boost your learning journey.

Leave a Reply

Your email address will not be published. Required fields are marked *