Difference between revisions of "Python-for-Automation/C3/Spelling-and-Grammar-Checker/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 2: Line 2:
  
  
<div style="margin-left:1.27cm;margin-right:0cm;"></div>
+
 
{| border="1"
+
{| border= 1
 
|-
 
|-
 
|| '''Visual Cue'''
 
|| '''Visual Cue'''
 
|| '''Narration'''
 
|| '''Narration'''
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show slide:'''
+
|| '''Show slide:'''
  
 
Welcome
 
Welcome
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Welcome to the Spoken Tutorial on '''Spelling and Grammar Checker'''
+
|| Welcome to the Spoken Tutorial on '''Spelling and Grammar Checker'''
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show slide:'''
+
|| '''Show slide:'''
  
 
Learning Objectives
 
Learning Objectives
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | In this tutorial, we will learn to
+
|| In this tutorial, we will learn to
 
* Create functions to identify spelling and grammar errors
 
* Create functions to identify spelling and grammar errors
 
* Implement text processing techniques in Python
 
* Implement text processing techniques in Python
 
* Create a '''GUI application '''with a text area and buttons
 
* Create a '''GUI application '''with a text area and buttons
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show slide:'''
+
|| '''Show slide:'''
  
 
System Requirements
 
System Requirements
Line 29: Line 29:
 
'''Python 3.12.3'''
 
'''Python 3.12.3'''
  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | To record this tutorial, I am using
+
|| To record this tutorial, I am using
* '''Ubuntu Linux OS version 22.04'''</div>
+
* '''Ubuntu Linux OS version 22.04'''
* '''Python 3.12.3'''</div>
+
* '''Python 3.12.3'''
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show slide:'''
+
|| '''Show slide:'''
  
 
Prerequisite
 
Prerequisite
  
 
[https://www.spoken-tutorial.org/ https:/spoken-tutorial.org]
 
[https://www.spoken-tutorial.org/ https:/spoken-tutorial.org]
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | To follow this tutorial:
+
|| To follow this tutorial:
 
* You must have basic knowledge of using '''Linux Terminal and Python'''
 
* You must have basic knowledge of using '''Linux Terminal and Python'''
 
* For pre-requisite '''Linux and Python Tutorials''', please visit this website
 
* For pre-requisite '''Linux and Python Tutorials''', please visit this website
 
* '''Python '''libraries required for '''automation '''must be installed
 
* '''Python '''libraries required for '''automation '''must be installed
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show slide:'''
+
|| '''Show slide:'''
  
 
Code files
 
Code files
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" |
+
||
 
* The files used in this tutorial are provided in the '''Code''''''files''' link.
 
* The files used in this tutorial are provided in the '''Code''''''files''' link.
  
Line 53: Line 53:
 
*Make a copy and then use them while practicing.
 
*Make a copy and then use them while practicing.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show Slide:'''
+
|| '''Show Slide:'''
  
 
Spelling and Grammar Checker - GUI
 
Spelling and Grammar Checker - GUI
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | In this tutorial we will build the '''GUI '''for a Spelling and Grammar checker as shown here.
+
|| In this tutorial we will build the '''GUI '''for a Spelling and Grammar checker as shown here.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Slide:'''
+
|| '''Slide:'''
  
 
Spelling and Grammar Checker
 
Spelling and Grammar Checker
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" |  
+
||  
* <div style="margin-left:1.27cm;margin-right:0cm;">The checker will refer to an inbuilt dictionary to identify wrong spellings</div>
+
* The checker will refer to an inbuilt dictionary to identify wrong spellings
* <div style="margin-left:1.27cm;margin-right:0cm;">It will use '''language_tool_python''' to recognize incorrect grammar and suggest corrections</div>
+
* It will use '''language_tool_python''' to recognize incorrect grammar and suggest corrections
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show Slide:'''
+
|| '''Show Slide:'''
  
 
Spelling and Grammar Checker - Libraries
 
Spelling and Grammar Checker - Libraries
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | The following '''Python libraries''' are required for this tutorial:
+
|| The following '''Python libraries''' are required for this tutorial:
* <div style="margin-left:1.27cm;margin-right:0cm;">'''Language_tool_python '''provides grammar and style checking capabilities.</div>
+
* '''Language_tool_python '''provides grammar and style checking capabilities.
* <div style="margin-left:1.27cm;margin-right:0cm;">'''NLTK '''is a '''library '''for text processing and natural language understanding tasks.</div>
+
* '''NLTK '''is a '''library '''for text processing and natural language understanding tasks.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show Slide:'''
+
|| '''Show Slide:'''
  
 
Spelling and Grammar Checker - Libraries
 
Spelling and Grammar Checker - Libraries
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" |
+
||
* <div style="margin-left:1.27cm;margin-right:0cm;">'''re '''module''' '''helps to manipulate '''strings '''based on patterns using '''regular expressions'''.</div>
+
* '''re '''module''' '''helps to manipulate '''strings '''based on patterns using '''regular expressions'''.
* <div style="margin-left:1.27cm;margin-right:0cm;">'''tkinter '''is the standard '''GUI toolkit '''for '''Python'''.</div>
+
* '''tkinter '''is the standard '''GUI toolkit '''for '''Python'''.
* <div style="margin-left:1.27cm;margin-right:0cm;">'''docx''' is for reading and writing Microsoft Word files.</div>
+
* '''docx''' is for reading and writing Microsoft Word files.
* <div style="margin-left:1.27cm;margin-right:0cm;">'''Fitz (PyMuPDF)''' is for reading PDF files</div>
+
* '''Fitz (PyMuPDF)''' is for reading PDF files
  
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Slide: Install java and tkinter'''
+
|| '''Slide: Install java and tkinter'''
  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Note that '''Java '''and '''tkinter '''must be installed for this tutorial.  
+
|| Note that '''Java '''and '''tkinter '''must be installed for this tutorial.  
  
 
If not, please install using the below commands.
 
If not, please install using the below commands.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Point to the file in downloads folder'''
+
|| '''Point to the file in downloads folder'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | I have created the source code '''checker.py''' for this demonstration.
+
|| I have created the source code '''checker.py''' for this demonstration.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Open checker.py file'''
+
|| '''Open checker.py file'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Now, let us go through the code in the text editor.
+
|| Now, let us go through the code in the text editor.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
import re
+
'''import re'''
import tkinter as tk
+
'''import tkinter as tk'''
from tkinter import scrolledtext, filedialog
+
'''from tkinter import scrolledtext, filedialog'''
from nltk.corpus import words
+
'''from nltk.corpus import words'''
import nltk
+
'''import nltk'''
import language_tool_python
+
'''import language_tool_python'''
import docx
+
'''import docx'''
import fitz
+
'''import fitz'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | First we need to '''import''' the necessary '''modules'''.
+
|| First we need to '''import''' the necessary '''modules'''.
  
 
This helps to create scrollable text areas and file dialogs.
 
This helps to create scrollable text areas and file dialogs.
Line 110: Line 110:
 
It also provides access to Python’s inbuilt spelling dictionary and grammar library.
 
It also provides access to Python’s inbuilt spelling dictionary and grammar library.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
try:
 
try:
  
nltk.download('words')
+
'''nltk.download('words')'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | First, we download the ''''words' corpus''' from '''NLTK'''.
+
|| First, we download the ''''words' corpus''' from '''NLTK'''.
  
 
This '''corpus''' has a large collection of English words used for spell-checking.
 
This '''corpus''' has a large collection of English words used for spell-checking.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
except Exception as e:
 
except Exception as e:
  
print(f"NLTK Download Error: {e}")
+
'''print(f"NLTK Download Error: {e}")'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Here, the '''exception block''' catches any errors that may occur in the '''try block'''.
+
|| Here, the '''exception block''' catches any errors that may occur in the '''try block'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
try:
 
try:
  
 
tool = language_tool_python .LanguageTool('en-US')
 
tool = language_tool_python .LanguageTool('en-US')
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Next, we initialize an instance of '''LanguageTool'''.
+
|| Next, we initialize an instance of '''LanguageTool'''.
  
 
It checks grammar and style according to '''US English'''.
 
It checks grammar and style according to '''US English'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
except language_tool_python.ServerException as e: print(f"Language Tool Initialization Error: {e}")
 
except language_tool_python.ServerException as e: print(f"Language Tool Initialization Error: {e}")
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | This block handles exceptions raised by the '''LanguageTool '''during its initialization.
+
|| This block handles exceptions raised by the '''LanguageTool '''during its initialization.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
def checkSpelling(text):
 
def checkSpelling(text):
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''checkSpelling''' function checks the spelling in the given text.
+
|| '''checkSpelling''' function checks the spelling in the given text.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
wordList = set(words.words())
 
wordList = set(words.words())
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Here the list of words from the '''NLTK corpus''' is converted into a set.
+
|| Here the list of words from the '''NLTK corpus''' is converted into a set.
  
 
A set will allow for faster look-up.
 
A set will allow for faster look-up.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
misspelled = []
 
misspelled = []
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Initialize a list which will store all the misspelled words in the text.
+
|| Initialize a list which will store all the misspelled words in the text.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
for word in re.findall(r'\b\w+\b', text):
 
for word in re.findall(r'\b\w+\b', text):
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Then we run a '''for loop''' to iterate through each word in the text.
+
|| Then we run a '''for loop''' to iterate through each word in the text.
  
 
'''re.findall''' method finds all words in the text using '''regular expressions'''.
 
'''re.findall''' method finds all words in the text using '''regular expressions'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
if word.lower() not in wordList:
 
if word.lower() not in wordList:
Line 171: Line 171:
  
 
return misspelled
 
return misspelled
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Each '''word''' is converted to lowercase and checked against the '''wordList.'''
+
|| Each '''word''' is converted to lowercase and checked against the '''wordList.'''
  
 
If the '''word''' is not found in the '''wordList''', it is added to the '''misspelled''' list.
 
If the '''word''' is not found in the '''wordList''', it is added to the '''misspelled''' list.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
def checkGrammar(text):
 
def checkGrammar(text):
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Next, '''the checkGrammar''' function checks the grammar in the text.
+
|| Next, '''the checkGrammar''' function checks the grammar in the text.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
matches = tool.check(text) return matches
 
matches = tool.check(text) return matches
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''check '''is a method of the '''LanguageTool '''that checks the text for grammatical errors.
+
|| '''check '''is a method of the '''LanguageTool '''that checks the text for grammatical errors.
  
 
We store the result of the grammar check in a variable named '''matches'''.
 
We store the result of the grammar check in a variable named '''matches'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
def checkText():
 
def checkText():
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''checkText '''function combines the grammar and spelling checks and displays results.
+
|| '''checkText '''function combines the grammar and spelling checks and displays results.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
text = textArea.get("1.0", tk.END)
 
text = textArea.get("1.0", tk.END)
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''get method''' retrieves all the text from the '''text area'''.
+
|| '''get method''' retrieves all the text from the '''text area'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
“1.0”
 
“1.0”
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Here, '''1 point 0''' is a textual representation of a position in the '''text '''widget.
+
|| Here, '''1 point 0''' is a textual representation of a position in the '''text '''widget.
  
 
It points to the beginning of the first line.
 
It points to the beginning of the first line.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
spellingErrors = checkSpelling(text)
 
spellingErrors = checkSpelling(text)
  
 
grammarErrors = checkGrammar(text)
 
grammarErrors = checkGrammar(text)
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | We call the '''checkSpelling function''' and the '''checkGrammar function'''.
+
|| We call the '''checkSpelling function''' and the '''checkGrammar function'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
result = "Spelling Errors:\n"
 
result = "Spelling Errors:\n"
Line 220: Line 220:
  
 
else: result += "None"
 
else: result += "None"
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | If there are any spelling errors we append them to a string named '''result'''.
+
|| If there are any spelling errors we append them to a string named '''result'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
 
result += "\n\nGrammar Errors:\n"
 
result += "\n\nGrammar Errors:\n"
 
if grammarErrors:
 
if grammarErrors:
Line 228: Line 228:
 
result += f"{match.context} -> {match.message}\n"
 
result += f"{match.context} -> {match.message}\n"
 
else: result += "None"
 
else: result += "None"
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Then, we iterate through any grammar errors and append them to '''result'''.
+
|| Then, we iterate through any grammar errors and append them to '''result'''.
  
 
If no errors are found, the word '''None''' is appended to '''result'''.
 
If no errors are found, the word '''None''' is appended to '''result'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
resultArea.config(state=tk.NORMAL)
 
resultArea.config(state=tk.NORMAL)
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Next, we add commands to configure the '''resultArea'''.
+
|| Next, we add commands to configure the '''resultArea'''.
  
 
In the '''config method '''set the '''state '''to '''tk dot NORMAL '''to make the result area editable.
 
In the '''config method '''set the '''state '''to '''tk dot NORMAL '''to make the result area editable.
Line 241: Line 241:
 
This will allow the program to print the error results in the result area.
 
This will allow the program to print the error results in the result area.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
resultArea.delete("1.0", tk.END)
 
resultArea.delete("1.0", tk.END)
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''delete method''' clears text from the specified start position to end position in the result area
+
|| '''delete method''' clears text from the specified start position to end position in the result area
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
resultArea.insert(tk.END, result)
 
resultArea.insert(tk.END, result)
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''insert method''' inserts the '''result string '''containing the errors into the '''result area'''.
+
|| '''insert method''' inserts the '''result string '''containing the errors into the '''result area'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
resultArea.config(state=tk.DISABLED)
 
resultArea.config(state=tk.DISABLED)
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Again, in the '''config method '''set the '''state '''to '''tk dot DISABLED '''to disable editing.
+
|| Again, in the '''config method '''set the '''state '''to '''tk dot DISABLED '''to disable editing.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
def uploadFile():
 
def uploadFile():
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''uploadFile''' function opens a file dialog box to upload a '''text''', '''Word''', or '''PDF '''file.
+
|| '''uploadFile''' function opens a file dialog box to upload a '''text''', '''Word''', or '''PDF '''file.
  
 
It reads the file content, and inserts it into the text area.
 
It reads the file content, and inserts it into the text area.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
file_path = filedialog.askopen filename(filetypes=[("Text files", "*.txt"), ("Word documents", "*.docx"), ("PDF files", "*.pdf")])
 
file_path = filedialog.askopen filename(filetypes=[("Text files", "*.txt"), ("Word documents", "*.docx"), ("PDF files", "*.pdf")])
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''askopenfilename '''opens a file dialog window that allows the user to select a file.
+
|| '''askopenfilename '''opens a file dialog window that allows the user to select a file.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
filetypes=[("Text files", "*.txt"), ("Word documents", "*.docx"), ("PDF files", "*.pdf")]
 
filetypes=[("Text files", "*.txt"), ("Word documents", "*.docx"), ("PDF files", "*.pdf")]
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''filetypes '''restricts the selectable files to '''text''', '''word '''or '''pdf '''files.
+
|| '''filetypes '''restricts the selectable files to '''text''', '''word '''or '''pdf '''files.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
if file_path:
 
if file_path:
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | This checks if a file is selected.
+
|| This checks if a file is selected.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
if file_path.endswith(".txt"):
 
if file_path.endswith(".txt"):
Line 285: Line 285:
  
 
text = file.read()
 
text = file.read()
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | First we check if the selected file is a '''text '''file.
+
|| First we check if the selected file is a '''text '''file.
  
 
If yes, then we open the file in '''read '''mode with '''UTF-8''' encoding.
 
If yes, then we open the file in '''read '''mode with '''UTF-8''' encoding.
Line 291: Line 291:
 
Then we read the entire content of the file into the variable '''text'''.
 
Then we read the entire content of the file into the variable '''text'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
elif file_path.endswith(".docx "): doc = docx.Document(file_ path) text = '\n'.join([para.text for para in doc.paragraphs])
 
elif file_path.endswith(".docx "): doc = docx.Document(file_ path) text = '\n'.join([para.text for para in doc.paragraphs])
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | If the selected file is not a '''text '''file, we check if it is a '''word '''document.
+
|| If the selected file is not a '''text '''file, we check if it is a '''word '''document.
  
 
Open the '''word '''document using the '''docx '''library.
 
Open the '''word '''document using the '''docx '''library.
Line 300: Line 300:
 
We then join all the content into the variable '''text'''.
 
We then join all the content into the variable '''text'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
elif file_path.endswith(".pdf"):
 
elif file_path.endswith(".pdf"):
Line 311: Line 311:
  
 
text += page.get_text()
 
text += page.get_text()
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | If the selected file is not a '''text '''or '''word '''file, we check if it is a '''PDF '''file.
+
|| If the selected file is not a '''text '''or '''word '''file, we check if it is a '''PDF '''file.
  
 
Open the '''PDF '''file using the '''fitz '''library.
 
Open the '''PDF '''file using the '''fitz '''library.
Line 317: Line 317:
 
Content from each page of the '''PDF '''is appended to the variable '''text'''.
 
Content from each page of the '''PDF '''is appended to the variable '''text'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
textArea.delete("1.0", tk.END)
 
textArea.delete("1.0", tk.END)
  
 
textArea.insert(tk.END, text)
 
textArea.insert(tk.END, text)
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Finally, we delete the current content of the text area.
+
|| Finally, we delete the current content of the text area.
  
 
Then we insert the content of the file into the text area.
 
Then we insert the content of the file into the text area.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
root = tk.Tk()
 
root = tk.Tk()
  
 
root.title("Spelling and Grammar Checker")
 
root.title("Spelling and Grammar Checker")
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Now, we initialize the main '''Tkinter''' window and call it '''root'''.
+
|| Now, we initialize the main '''Tkinter''' window and call it '''root'''.
  
 
'''root dot title''' sets the title of the window.
 
'''root dot title''' sets the title of the window.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
textArea = scrolledtext.ScrolledText(root, wrap=tk.WORD, width=60, height=15)
 
textArea = scrolledtext.ScrolledText(root, wrap=tk.WORD, width=60, height=15)
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | This creates a scrollable text area for user input.
+
|| This creates a scrollable text area for user input.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
textArea.pack(pady=10)
 
textArea.pack(pady=10)
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | We can also add padding to the text area using the '''pack method'''.
+
|| We can also add padding to the text area using the '''pack method'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
uploadButton = tk.Button (root, text="Upload", command=uploadFile)
 
uploadButton = tk.Button (root, text="Upload", command=uploadFile)
  
 
uploadButton.pack(pady=5)
 
uploadButton.pack(pady=5)
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Next, we create an '''upload button '''that invokes the '''uploadFile '''function.
+
|| Next, we create an '''upload button '''that invokes the '''uploadFile '''function.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
command=uploadFile
 
command=uploadFile
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | We can use the '''command attribute''' to set the '''function''' to be called.
+
|| We can use the '''command attribute''' to set the '''function''' to be called.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
checkButton = tk.Button(root, text="Check", command=checkText)
 
checkButton = tk.Button(root, text="Check", command=checkText)
  
 
checkButton.pack(pady=5)
 
checkButton.pack(pady=5)
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | We also need a '''check button''' which will trigger the '''checkText function'''.
+
|| We also need a '''check button''' which will trigger the '''checkText function'''.
  
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
resultArea = scrolledtext.Scro lledText(root,wrap=tk.WORD, width=60, height=15, state =tk.DISABLED)
 
resultArea = scrolledtext.Scro lledText(root,wrap=tk.WORD, width=60, height=15, state =tk.DISABLED)
  
 
resultArea.pack(pady=10)
 
resultArea.pack(pady=10)
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Finally, we create a result area using '''ScrolledText '''to display the results.
+
|| Finally, we create a result area using '''ScrolledText '''to display the results.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
state=tk.DISABLED
 
state=tk.DISABLED
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''state''' is set as '''tk dot DISABLED''' which disables the editing of the result area.
+
|| '''state''' is set as '''tk dot DISABLED''' which disables the editing of the result area.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
root.mainloop()
 
root.mainloop()
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | This starts the '''Tkinter''' event loop and keeps the window open for user interaction.
+
|| This starts the '''Tkinter''' event loop and keeps the window open for user interaction.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Running the code:'''
+
|| '''Running the code:'''
  
 
Open terminal -
 
Open terminal -
  
 
Press Ctrl + Alt + T
 
Press Ctrl + Alt + T
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | Save the code as '''checker.py '''in the '''Downloads''' folder.
+
|| Save the code as '''checker.py '''in the '''Downloads''' folder.
  
 
Open the '''terminal''' by pressing '''Control, Alt and T '''keys simultaneously.
 
Open the '''terminal''' by pressing '''Control, Alt and T '''keys simultaneously.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Type in terminal:'''
+
|| '''Type in terminal:'''
  
 
source Automation/bin/activate
 
source Automation/bin/activate
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | We will open the '''virtual environment''' we created for the '''Automation '''series.
+
|| We will open the '''virtual environment''' we created for the '''Automation '''series.
  
 
Type '''source space Automation forward slash bin forward slash activate'''.
 
Type '''source space Automation forward slash bin forward slash activate'''.
Line 400: Line 400:
 
Then press '''enter'''.
 
Then press '''enter'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Type in terminal:'''
+
|| '''Type in terminal:'''
  
 
> cd Downloads
 
> cd Downloads
  
 
> Python3 checker.py
 
> Python3 checker.py
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | <div style="color:#000000;">In the terminal, type '''cd Downloads '''and press enter'''.'''</div>
+
|| In the terminal, type '''cd Downloads '''and press enter'''.'''
  
<div style="color:#000000;">Next type '''python3 checker.py''' and press enter.</div>
+
Next type '''python3 checker.py''' and press enter.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show tkinter window:'''
+
|| '''Show tkinter window:'''
  
 
Tkinter window opens up on running the code
 
Tkinter window opens up on running the code
  
  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | <div style="color:#000000;">(pause here)Wait for a moment as it may take a while for the '''Tkinter '''window to appear.</div>
+
|| (pause here)Wait for a moment as it may take a while for the '''Tkinter '''window to appear.
  
<div style="color:#000000;">The '''tkinter window''' will pop up once the code is executed.</div>
+
The '''tkinter window''' will pop up once the code is executed.
  
<div style="color:#000000;">As you can see, there is a '''text area''', an '''upload and check button''' and a '''result area'''.</div>
+
As you can see, there is a '''text area''', an '''upload and check button''' and a '''result area'''.
  
<div style="color:#000000;">Let us test out our '''Spelling and Grammar checker application.'''</div>
+
Let us test out our '''Spelling and Grammar checker application.'''
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Type in tkinter window:'''
+
|| '''Type in tkinter window:'''
  
 
Hello wrold.
 
Hello wrold.
Line 429: Line 429:
  
 
'''Highlight:'''
 
'''Highlight:'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | <div style="color:#000000;">We are going to type '''Hello wrold''' and click on the '''Check button'''.</div>
+
|| We are going to type '''Hello wrold''' and click on the '''Check button'''.
  
<div style="color:#000000;">In the result area, we can see that the wrong spelling of '''world '''has been detected.</div>
+
In the result area, we can see that the wrong spelling of '''world '''has been detected.
  
<div style="color:#000000;">Let us correct the spelling of '''world'''.</div>
+
Let us correct the spelling of '''world'''.
  
<div style="color:#000000;">Now click on the check button.</div>
+
Now click on the check button.
  
<div style="color:#000000;">We can see there are no errors.</div>
+
We can see there are no errors.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Type in tkinter window:'''
+
|| '''Type in tkinter window:'''
  
 
What is you favorite lanugage
 
What is you favorite lanugage
Line 447: Line 447:
 
'''Highlight:'''
 
'''Highlight:'''
  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | <div style="color:#000000;">Now let us type '''what is you favorite lanugage''' and click on '''Check'''.</div>
+
|| Now let us type '''what is you favorite lanugage''' and click on '''Check'''.
  
<div style="color:#000000;">This time we can see grammar and spelling errors.</div>
+
This time we can see grammar and spelling errors.
  
<div style="color:#000000;">In the result area, corrections for the errors are also suggested.</div>
+
In the result area, corrections for the errors are also suggested.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Correct text in tkinter window:'''
+
|| '''Correct text in tkinter window:'''
  
 
Hello world. Python is my favorite language
 
Hello world. Python is my favorite language
Line 462: Line 462:
  
 
Content in result area
 
Content in result area
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | <div style="color:#000000;">Let us fix the errors we see.</div>
+
|| Let us fix the errors we see.
  
<div style="color:#000000;">The correct sentence would be '''What is your favorite language'''. (correct this first)</div>
+
The correct sentence would be '''What is your favorite language'''. (correct this first)
  
<div style="color:#000000;">Click on '''Check'''. (then correct this)</div>
+
Click on '''Check'''. (then correct this)
  
<div style="color:#000000;">Now there are no errors, so the result area displays '''None'''.</div>
+
Now there are no errors, so the result area displays '''None'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" |
+
||
  * <div style="margin-left:1.27cm;margin-right:0cm;">'''Click on upload button'''</div>
+
  * '''Click on upload button'''
* <div style="margin-left:1.27cm;margin-right:0cm;">'''Select file type'''</div>
+
* '''Select file type'''
* <div style="margin-left:1.27cm;margin-right:0cm;">'''Select file'''</div>
+
* '''Select file'''
* <div style="margin-left:1.27cm;margin-right:0cm;">'''Click Open'''</div>
+
* '''Click Open'''
  
  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | <div style="color:#000000;">Click on the '''Upload button '''and a file dialog box will appear on your screen.</div>
+
|| Click on the '''Upload button '''and a file dialog box will appear on your screen.
  
<div style="color:#000000;">Here we can select the type of file we want to upload.</div>
+
Here we can select the type of file we want to upload.
  
<div style="color:#000000;">Let us select this '''paragraph.txt '''file and click on '''Open'''.</div>
+
Let us select this '''paragraph.txt '''file and click on '''Open'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
  
 
Content in text area
 
Content in text area
Line 492: Line 492:
  
 
Content in result area
 
Content in result area
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | <div style="color:#000000;">We see that the content of the '''paragraph.txt '''file has appeared in the text area.</div>
+
|| We see that the content of the '''paragraph.txt '''file has appeared in the text area.
  
<div style="color:#000000;">Click on the '''Check button'''.</div>
+
Click on the '''Check button'''.
  
<div style="color:#000000;">Please wait as it might take some time to process the spell check.</div>
+
Please wait as it might take some time to process the spell check.
  
<div style="color:#000000;">Some spelling and grammar errors are displayed in the result area.</div>
+
Some spelling and grammar errors are displayed in the result area.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Highlight:'''
+
|| '''Highlight:'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;color:#000000;" | We can now edit the text, based on the errors and suggestions pointed out in the result area.
+
|| We can now edit the text, based on the errors and suggestions pointed out in the result area.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Close tkinter window'''
+
|| '''Close tkinter window'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;color:#000000;" | We can terminate this program by closing the '''tkinter window'''.
+
|| We can terminate this program by closing the '''tkinter window'''.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Type in terminal:'''
+
|| '''Type in terminal:'''
  
 
deactivate
 
deactivate
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;color:#000000;" | In the terminal, type '''deactivate'''.This will allow you to exit the virtual environment.
+
|| In the terminal, type '''deactivate'''.This will allow you to exit the virtual environment.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show slide:'''
+
|| '''Show slide:'''
  
 
Summary
 
Summary
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | <div style="color:#000000;">This brings us to the end of the tutorial. Let us summarize.</div>
+
|| This brings us to the end of the tutorial.
 +
Let us summarize.
  
<div style="color:#000000;">In this tutorial, we have learnt to</div>
+
In this tutorial, we have learnt to
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Create functions to identify spelling and grammar errors</div>
+
* Create functions to identify spelling and grammar errors
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Implement text processing techniques in Python</div>
+
* Implement text processing techniques in Python
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Create a '''GUI application '''with a text area and buttons</div>
+
* Create a '''GUI application '''with a text area and buttons
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show slide:'''
+
|| '''Show slide:'''
  
 
Assignment
 
Assignment
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | As an assignment, do the following:
+
|| As an assignment, do the following:
* <div style="margin-left:1.27cm;margin-right:0cm;">Modify the '''checker.py '''and''' '''print the total number of errors in the result area.</div>
+
* Modify the '''checker.py '''and''' '''print the total number of errors in the result area.
* <div style="margin-left:1.27cm;margin-right:0cm;">Hint: Use the '''len '''function to calculate the number of errors.</div>
+
* Hint: Use the '''len '''function to calculate the number of errors.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show slide:'''
+
|| '''Show slide:'''
  
 
About the Spoken Tutorial Project
 
About the Spoken Tutorial Project
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | The video at the following link summarizes the '''Spoken Tutorial Project.'''Please download and watch it
+
|| The video at the following link summarizes the '''Spoken Tutorial Project.'''Please download and watch it
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show Slide:'''
+
|| '''Show Slide:'''
  
 
Spoken Tutorial Workshops
 
Spoken Tutorial Workshops
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | The '''Spoken Tutorial Project''' team conducts workshops and gives certificates.
+
|| The '''Spoken Tutorial Project''' team conducts workshops and gives certificates.
  
 
For more details, please write to us.
 
For more details, please write to us.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #808080;border-left:1pt solid #808080;border-right:1pt solid #808080;padding:0.176cm;" | '''Show Slide: '''Answers for THIS Spoken Tutorial
+
|| Please post your timed queries in this forum.
| style="border-top:none;border-bottom:1pt solid #808080;border-left:none;border-right:1pt solid #808080;padding:0.176cm;" | Please post your timed queries in this forum.
+
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show Slide:'''
+
|| '''Show Slide:'''
  
 
FOSSEE Forum
 
FOSSEE Forum
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | For any general or technical questions on''' Python for Automation''', visit the '''FOSSEE forum''' and post your question.
+
|| For any general or technical questions on''' Python for Automation''', visit the '''FOSSEE forum''' and post your question.
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show slide:'''
+
|| '''Show slide:'''
  
 
Acknowledgement
 
Acknowledgement
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''The Spoken Tutorial Project''' was established by the '''Ministry of Education, Government of India.'''
+
|| '''The Spoken Tutorial Project''' was established by the '''Ministry of Education, Government of India.'''
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | '''Show slide:'''
+
|| '''Show slide:'''
  
 
Thank You
 
Thank You
| style="border-top:none;border-bottom:1pt solid #000000;border-left:none;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.176cm;padding-right:0.176cm;" | This is '''Jasmine Tresa Jose''', a '''FOSSEE Semester Long Intern 2024, IIT Bombay''' signing off.
+
|| This is '''Jasmine Tresa Jose''', a '''FOSSEE Semester Long Intern 2024, IIT Bombay''' signing off.
  
 
Thanks for joining.
 
Thanks for joining.
 
|-
 
|-
 
|}
 
|}

Revision as of 11:27, 3 September 2024



Visual Cue Narration
Show slide:

Welcome

Welcome to the Spoken Tutorial on Spelling and Grammar Checker
Show slide:

Learning Objectives

In this tutorial, we will learn to
  • Create functions to identify spelling and grammar errors
  • Implement text processing techniques in Python
  • Create a GUI application with a text area and buttons
Show slide:

System Requirements

Ubuntu Linux OS 22.04

Python 3.12.3

To record this tutorial, I am using
  • Ubuntu Linux OS version 22.04
  • Python 3.12.3
Show slide:

Prerequisite

https:/spoken-tutorial.org

To follow this tutorial:
  • You must have basic knowledge of using Linux Terminal and Python
  • For pre-requisite Linux and Python Tutorials, please visit this website
  • Python libraries required for automation must be installed
Show slide:

Code files

  • The files used in this tutorial are provided in the Code'files' link.
  • Please download and extract the files.
  • Make a copy and then use them while practicing.
Show Slide:

Spelling and Grammar Checker - GUI

In this tutorial we will build the GUI for a Spelling and Grammar checker as shown here.
Slide:

Spelling and Grammar Checker

  • The checker will refer to an inbuilt dictionary to identify wrong spellings
  • It will use language_tool_python to recognize incorrect grammar and suggest corrections
Show Slide:

Spelling and Grammar Checker - Libraries

The following Python libraries are required for this tutorial:
  • Language_tool_python provides grammar and style checking capabilities.
  • NLTK is a library for text processing and natural language understanding tasks.
Show Slide:

Spelling and Grammar Checker - Libraries

  • re module helps to manipulate strings based on patterns using regular expressions.
  • tkinter is the standard GUI toolkit for Python.
  • docx is for reading and writing Microsoft Word files.
  • Fitz (PyMuPDF) is for reading PDF files
Slide: Install java and tkinter Note that Java and tkinter must be installed for this tutorial.

If not, please install using the below commands.

Point to the file in downloads folder I have created the source code checker.py for this demonstration.
Open checker.py file Now, let us go through the code in the text editor.
Highlight:

import re import tkinter as tk from tkinter import scrolledtext, filedialog from nltk.corpus import words import nltk import language_tool_python import docx import fitz

First we need to import the necessary modules.

This helps to create scrollable text areas and file dialogs.

It also provides access to Python’s inbuilt spelling dictionary and grammar library.

Highlight:

try:

nltk.download('words')

First, we download the 'words' corpus from NLTK.

This corpus has a large collection of English words used for spell-checking.

Highlight:

except Exception as e:

print(f"NLTK Download Error: {e}")

Here, the exception block catches any errors that may occur in the try block.
Highlight:

try:

tool = language_tool_python .LanguageTool('en-US')

Next, we initialize an instance of LanguageTool.

It checks grammar and style according to US English.

Highlight:

except language_tool_python.ServerException as e: print(f"Language Tool Initialization Error: {e}")

This block handles exceptions raised by the LanguageTool during its initialization.
Highlight:

def checkSpelling(text):

checkSpelling function checks the spelling in the given text.
Highlight:

wordList = set(words.words())

Here the list of words from the NLTK corpus is converted into a set.

A set will allow for faster look-up.

Highlight:

misspelled = []

Initialize a list which will store all the misspelled words in the text.
Highlight:

for word in re.findall(r'\b\w+\b', text):

Then we run a for loop to iterate through each word in the text.

re.findall method finds all words in the text using regular expressions.

Highlight:

if word.lower() not in wordList:

misspelled.append(word)

return misspelled

Each word is converted to lowercase and checked against the wordList.

If the word is not found in the wordList, it is added to the misspelled list.

Highlight:

def checkGrammar(text):

Next, the checkGrammar function checks the grammar in the text.
Highlight:

matches = tool.check(text) return matches

check is a method of the LanguageTool that checks the text for grammatical errors.

We store the result of the grammar check in a variable named matches.

Highlight:

def checkText():

checkText function combines the grammar and spelling checks and displays results.
Highlight:

text = textArea.get("1.0", tk.END)

get method retrieves all the text from the text area.
Highlight:

“1.0”

Here, 1 point 0 is a textual representation of a position in the text widget.

It points to the beginning of the first line.

Highlight:

spellingErrors = checkSpelling(text)

grammarErrors = checkGrammar(text)

We call the checkSpelling function and the checkGrammar function.
Highlight:

result = "Spelling Errors:\n"

if spellingErrors:

result += ", ".join(spellingErrors)

else: result += "None"

If there are any spelling errors we append them to a string named result.
Highlight:

result += "\n\nGrammar Errors:\n" if grammarErrors: for match in grammarErrors: result += f"{match.context} -> {match.message}\n" else: result += "None"

Then, we iterate through any grammar errors and append them to result.

If no errors are found, the word None is appended to result.

Highlight:

resultArea.config(state=tk.NORMAL)

Next, we add commands to configure the resultArea.

In the config method set the state to tk dot NORMAL to make the result area editable.

This will allow the program to print the error results in the result area.

Highlight:

resultArea.delete("1.0", tk.END)

delete method clears text from the specified start position to end position in the result area
Highlight:

resultArea.insert(tk.END, result)

insert method inserts the result string containing the errors into the result area.
Highlight:

resultArea.config(state=tk.DISABLED)

Again, in the config method set the state to tk dot DISABLED to disable editing.
Highlight:

def uploadFile():

uploadFile function opens a file dialog box to upload a text, Word, or PDF file.

It reads the file content, and inserts it into the text area.

Highlight:

file_path = filedialog.askopen filename(filetypes=[("Text files", "*.txt"), ("Word documents", "*.docx"), ("PDF files", "*.pdf")])

askopenfilename opens a file dialog window that allows the user to select a file.
Highlight:

filetypes=[("Text files", "*.txt"), ("Word documents", "*.docx"), ("PDF files", "*.pdf")]

filetypes restricts the selectable files to text, word or pdf files.
Highlight:

if file_path:

This checks if a file is selected.
Highlight:

if file_path.endswith(".txt"):

with open(file_path, 'r', encoding='utf-8') as file:

text = file.read()

First we check if the selected file is a text file.

If yes, then we open the file in read mode with UTF-8 encoding.

Then we read the entire content of the file into the variable text.

Highlight:

elif file_path.endswith(".docx "): doc = docx.Document(file_ path) text = '\n'.join([para.text for para in doc.paragraphs])

If the selected file is not a text file, we check if it is a word document.

Open the word document using the docx library.

We then join all the content into the variable text.

Highlight:

elif file_path.endswith(".pdf"):

pdf_document = fitz.open (file_path) text = ""

for page_num in range(pdf_ document.page_count):

page = pdf_document.load_ page(page_num)

text += page.get_text()

If the selected file is not a text or word file, we check if it is a PDF file.

Open the PDF file using the fitz library.

Content from each page of the PDF is appended to the variable text.

Highlight:

textArea.delete("1.0", tk.END)

textArea.insert(tk.END, text)

Finally, we delete the current content of the text area.

Then we insert the content of the file into the text area.

Highlight:

root = tk.Tk()

root.title("Spelling and Grammar Checker")

Now, we initialize the main Tkinter window and call it root.

root dot title sets the title of the window.

Highlight:

textArea = scrolledtext.ScrolledText(root, wrap=tk.WORD, width=60, height=15)

This creates a scrollable text area for user input.
Highlight:

textArea.pack(pady=10)

We can also add padding to the text area using the pack method.
Highlight:

uploadButton = tk.Button (root, text="Upload", command=uploadFile)

uploadButton.pack(pady=5)

Next, we create an upload button that invokes the uploadFile function.
Highlight:

command=uploadFile

We can use the command attribute to set the function to be called.
Highlight:

checkButton = tk.Button(root, text="Check", command=checkText)

checkButton.pack(pady=5)

We also need a check button which will trigger the checkText function.
Highlight:

resultArea = scrolledtext.Scro lledText(root,wrap=tk.WORD, width=60, height=15, state =tk.DISABLED)

resultArea.pack(pady=10)

Finally, we create a result area using ScrolledText to display the results.
Highlight:

state=tk.DISABLED

state is set as tk dot DISABLED which disables the editing of the result area.
Highlight:

root.mainloop()

This starts the Tkinter event loop and keeps the window open for user interaction.
Running the code:

Open terminal -

Press Ctrl + Alt + T

Save the code as checker.py in the Downloads folder.

Open the terminal by pressing Control, Alt and T keys simultaneously.

Type in terminal:

source Automation/bin/activate

We will open the virtual environment we created for the Automation series.

Type source space Automation forward slash bin forward slash activate.

Then press enter.

Type in terminal:

> cd Downloads

> Python3 checker.py

In the terminal, type cd Downloads and press enter.

Next type python3 checker.py and press enter.

Show tkinter window:

Tkinter window opens up on running the code


(pause here)Wait for a moment as it may take a while for the Tkinter window to appear.

The tkinter window will pop up once the code is executed.

As you can see, there is a text area, an upload and check button and a result area.

Let us test out our Spelling and Grammar checker application.

Type in tkinter window:

Hello wrold.

Click on check button

Highlight:

We are going to type Hello wrold and click on the Check button.

In the result area, we can see that the wrong spelling of world has been detected.

Let us correct the spelling of world.

Now click on the check button.

We can see there are no errors.

Type in tkinter window:

What is you favorite lanugage

Click on check button

Highlight:

Now let us type what is you favorite lanugage and click on Check.

This time we can see grammar and spelling errors.

In the result area, corrections for the errors are also suggested.

Correct text in tkinter window:

Hello world. Python is my favorite language

Click on check button

Highlight:

Content in result area

Let us fix the errors we see.

The correct sentence would be What is your favorite language. (correct this first)

Click on Check. (then correct this)

Now there are no errors, so the result area displays None.

* Click on upload button
  • Select file type
  • Select file
  • Click Open


Click on the Upload button and a file dialog box will appear on your screen.

Here we can select the type of file we want to upload.

Let us select this paragraph.txt file and click on Open.

Highlight:

Content in text area

Click Check button

Highlight:

Content in result area

We see that the content of the paragraph.txt file has appeared in the text area.

Click on the Check button.

Please wait as it might take some time to process the spell check.

Some spelling and grammar errors are displayed in the result area.

Highlight: We can now edit the text, based on the errors and suggestions pointed out in the result area.
Close tkinter window We can terminate this program by closing the tkinter window.
Type in terminal:

deactivate

In the terminal, type deactivate.This will allow you to exit the virtual environment.
Show slide:

Summary

This brings us to the end of the tutorial.

Let us summarize.

In this tutorial, we have learnt to

  • Create functions to identify spelling and grammar errors
  • Implement text processing techniques in Python
  • Create a GUI application with a text area and buttons
Show slide:

Assignment

As an assignment, do the following:
  • Modify the checker.py and print the total number of errors in the result area.
  • Hint: Use the len function to calculate the number of errors.
Show slide:

About the Spoken Tutorial Project

The video at the following link summarizes the Spoken Tutorial Project.Please download and watch it
Show Slide:

Spoken Tutorial Workshops

The Spoken Tutorial Project team conducts workshops and gives certificates.

For more details, please write to us.

Please post your timed queries in this forum.
Show Slide:

FOSSEE Forum

For any general or technical questions on Python for Automation, visit the FOSSEE forum and post your question.
Show slide:

Acknowledgement

The Spoken Tutorial Project was established by the Ministry of Education, Government of India.
Show slide:

Thank You

This is Jasmine Tresa Jose, a FOSSEE Semester Long Intern 2024, IIT Bombay signing off.

Thanks for joining.

Contributors and Content Editors

Madhurig, Nirmala Venkat