Python Spell Corrector – Spelling Mistakes, Be Gone!
FREE Online Courses: Dive into Knowledge for Free. Learn More!
Spelling mistakes should never be present in writing to ensure that the reader understands what is being said. But because we are all human, we all occasionally make mistakes. The development of spell checkers is due to this. Spell Corrector, often known as Spell Checker, is a Python application that determines whether or not a word has the correct spelling.
About Python Spell Corrector
We will use Python’s Tkinter and TextBlob libraries to create this project. We construct the GUI that accepts user input and displays the results based on the spelling entered using the Tkinter module. Then we’ll use the TextBlob module to check the input word.
Prerequisites for Spell Corrector Using Python
- Basic knowledge of the Python programming language and how functions are defined in it.
- How the window is made in Tkinter GUI and how the frame is made in it
- How to work with the TextBlob library
Download Python Spell Corrector Project
Please download the source code of Python Spell Corrector Project: Python Spell Corrector Project Code
Steps to Create Spell Corrector Project Using Python
Following are the steps for developing the Python Spell Corrector Project:
Step 1: Importing the necessary modules
Step 2: Making a window for our project
Step 3: Functions
Step 4: Making Frames and Mapping the Buttons to Their Functionalities
Step 1: Importing the necessary modules
To use Tkinter, we need to import the Tkinter module. We are also going to import the TextBlob module to check if the input word is correct or not.
Code:
#import packages from textblob import TextBlob from tkinter import * import tkinter as tk
Step 2: Making a window for our project
This code sets the title of the window as ‘ProjectGurukul’, and sets the dimensions ‘width x length’.
Code:
checker = Tk() checker.geometry('500x500') checker.title("ProjectGurukul")
Step 3: Functions
This function gives the correct word as an output for the wrong input word.
Code:
def corrector(): input_word = Entry1.get() w = TextBlob(input_word) corrected_word = str(w.correct()) Entry2.delete(0, END) Entry2.insert(0, corrected_word)
Explanation:
We use entry.get() to get the input word and TextBlob to check if the word is correct or not, and if not, w.correct() to correct it.
Step 4: Making Frames and Mapping the Buttons to Their Functionalities
Now we add the required widgets for our GUI. We make a label to give heading to the Spell Checker, a frame1 to get an input word from the user by creating an entry widget, and after that, we create a button widget and assign the corrector function to it. At the end, we create a label for the output and display it by creating a second entry widget.
Code:
Label(checker, text="Spell Corrector", font="Arial 25 bold", fg="lightblue", bg="white").pack() frame1 = tk.Frame(checker) frame1.pack(pady=10) Label(frame1, text="Enter a word:", font="Arial 15").pack(side="left", pady=20) # create an input field for an input word that is incorrect. Entry1 = Entry(frame1, width=20) Entry1.pack(side="left", padx=10) frame2 = tk.Frame(checker) frame2.pack(pady=10) # create a button to correct the word Button(frame2, text="Correct It", font="Arial 15", command=corrector).pack(pady=10) # create a label to display the correct text Label(frame2, text="Correct words:", font="Arial 15").pack(pady=10) Entry2 = Entry(frame2, width=25) Entry2.pack(pady=10) # run the tkinter window checker.mainloop()
Full Code:
from textblob import TextBlob from tkinter import * import tkinter as tk checker = Tk() checker.geometry('500x500') checker.title("ProjectGurukul") def corrector(): input_word = Entry1.get() w = TextBlob(input_word) corrected_word = str(w.correct()) Entry2.delete(0, END) Entry2.insert(0, corrected_word) Label(checker, text="Spell Corrector", font="Arial 25 bold", fg="lightblue", bg="white").pack() frame1 = tk.Frame(checker) frame1.pack(pady=10) Label(frame1, text="Enter a word:", font="Arial 15").pack(side="left", pady=20) # create an input field for an input word that is incorrect. Entry1 = Entry(frame1, width=20) Entry1.pack(side="left", padx=10) frame2 = tk.Frame(checker) frame2.pack(pady=10) # create a button to correct the word Button(frame2, text="Correct It", font="Arial 15", command=corrector).pack(pady=10) # create a label to display the correct text Label(frame2, text="Correct words:", font="Arial 15").pack(pady=10) Entry2 = Entry(frame2, width=25) Entry2.pack(pady=10) # run the tkinter window checker.mainloop()
Python Spell Corrector Output:
Summary:
Using the Tkinter and TextBlob Python libraries, we were able to build the spell checker and correction project effectively. We acquired skills in GUI development, widget addition, and spelling checks. I hope you had fun creating with us!