From dccf70940ef45e0c410d8da8ce2e21aaa4ecdb3d Mon Sep 17 00:00:00 2001 From: Ananya Gupta <145869907+ananyag309@users.noreply.github.com> Date: Sun, 13 Oct 2024 21:37:32 +0530 Subject: [PATCH 1/2] Add files via upload --- Beginner_Projects/Spell Checker/README.md | 63 ++++ .../Spell Checker/spell_checker.py | 61 ++++ Beginner_Projects/Spell Checker/words.txt | 303 ++++++++++++++++++ 3 files changed, 427 insertions(+) create mode 100644 Beginner_Projects/Spell Checker/README.md create mode 100644 Beginner_Projects/Spell Checker/spell_checker.py create mode 100644 Beginner_Projects/Spell Checker/words.txt diff --git a/Beginner_Projects/Spell Checker/README.md b/Beginner_Projects/Spell Checker/README.md new file mode 100644 index 00000000..67a2c54d --- /dev/null +++ b/Beginner_Projects/Spell Checker/README.md @@ -0,0 +1,63 @@ +# Spell Checker Using Tkinter + +## Overview + +This project is a simple **Spell Checker** built using **Tkinter**, a GUI library in Python. The spell checker compares user-inputted words with a list of pre-defined words stored in a file named `words.txt`. If a word entered by the user doesn't match any word in the list, it is flagged as a misspelled word. + +## Features + +- **Graphical User Interface (GUI):** Built using Tkinter, the interface allows users to input text and check for spelling mistakes. +- **Text Comparison:** Words inputted by the user are compared against a predefined list of 300 words stored in `words.txt`. +- **Misspelled Word Highlighting:** If the user inputs a misspelled word, the program informs the user that the word is not found in the word list. + +## How It Works + +1. **`words.txt` File:** + - A text file (`words.txt`) contains a list of 300 common English words. This file serves as the dictionary that the program uses to verify the spelling of words. + + Example of a few words from `words.txt`: + ``` + apple + banana + computer + python + technology + ... + ``` + The complete file includes a wide range of words covering categories such as animals, objects, professions, and more. + +2. **Tkinter GUI:** + - A GUI is designed with `Tkinter`, allowing the user to input a sentence. The program then checks each word against the list in `words.txt`. + - The result will display whether each word is correct or if it is misspelled. + +3. **Spell Checker Logic:** + - The program reads the `words.txt` file and stores the words in a list. + - The input provided by the user is split into individual words. + - Each word is compared with the list of words from `words.txt`. If the word is not found, the program flags it as a misspelled word. + + +## How to Run the Project + +1. Clone the repository or download the project files. +2. Make sure the `words.txt` file is in the same directory as the Python script. +3. Run the `spell_checker.py` script using Python: + ``` + python spell_checker.py + ``` +4. Enter a sentence or a group of words in the input field of the GUI and click "Check Spelling." +5. The program will highlight any misspelled words. + +## Requirements + +- Python 3.x +- Tkinter library (included with Python) + +## Future Enhancements + +- **Dynamic Word Suggestions:** Add functionality to suggest correct words for misspelled words. +- **Custom Dictionary:** Allow users to add words to their custom dictionary. +- **Advanced Spell Check:** Include handling of punctuation and more advanced grammar rules. + + + + diff --git a/Beginner_Projects/Spell Checker/spell_checker.py b/Beginner_Projects/Spell Checker/spell_checker.py new file mode 100644 index 00000000..cefcb6f6 --- /dev/null +++ b/Beginner_Projects/Spell Checker/spell_checker.py @@ -0,0 +1,61 @@ +import tkinter as tk +from tkinter import messagebox + +# Load words from words.txt into a set for fast lookup +def load_words(): + with open("words.txt", "r") as file: + words = set(word.strip().lower() for word in file.readlines()) + return words + +# Check if the word is spelled correctly +def is_word_correct(word, word_list): + return word.lower() in word_list + +# Suggest corrections for the misspelled word +def suggest_corrections(word, word_list): + suggestions = [] + for w in word_list: + if abs(len(w) - len(word)) <= 1: # Find words of similar lengths + suggestions.append(w) + return suggestions + +# Check spelling when the button is pressed +def check_spelling(): + input_word = word_entry.get() + if not input_word: + messagebox.showwarning("Input Error", "Please enter a word.") + return + + if is_word_correct(input_word, word_list): + result_label.config(text=f"'{input_word}' is spelled correctly!", fg="green") + else: + result_label.config(text=f"'{input_word}' is not spelled correctly.", fg="red") + suggestions = suggest_corrections(input_word, word_list) + if suggestions: + result_label.config(text=f"'{input_word}' is not spelled correctly.\nDid you mean: {', '.join(suggestions[:5])}?", fg="red") + +# Load words list +word_list = load_words() + +# Initialize the Tkinter GUI window +root = tk.Tk() +root.title("Spell Checker") + +# Input Label +word_label = tk.Label(root, text="Enter a word:") +word_label.pack(pady=10) + +# Entry widget for user to input a word +word_entry = tk.Entry(root, width=40) +word_entry.pack(pady=5) + +# Button to check spelling +check_button = tk.Button(root, text="Check Spelling", command=check_spelling) +check_button.pack(pady=10) + +# Label to display the result +result_label = tk.Label(root, text="", font=("Helvetica", 14)) +result_label.pack(pady=20) + +# Start the Tkinter event loop +root.mainloop() diff --git a/Beginner_Projects/Spell Checker/words.txt b/Beginner_Projects/Spell Checker/words.txt new file mode 100644 index 00000000..2c334c2e --- /dev/null +++ b/Beginner_Projects/Spell Checker/words.txt @@ -0,0 +1,303 @@ +apple +banana +beautiful +car +dog +elephant +hello +world +python +java +javascript +coding +programming +tree +water +computer +keyboard +monitor +mouse +laptop +mobile +phone +tablet +charger +electricity +battery +window +door +building +city +town +village +country +continent +planet +universe +galaxy +star +moon +sun +cloud +rain +storm +snow +wind +summer +winter +spring +autumn +season +school +college +university +teacher +student +class +exam +test +assignment +project +research +study +homework +lesson +chapter +book +library +dictionary +encyclopedia +magazine +newspaper +article +journal +story +novel +author +writer +poet +poetry +drama +play +actor +actress +director +movie +film +music +song +instrument +guitar +piano +violin +drum +flute +trumpet +concert +festival +party +celebration +birthday +anniversary +wedding +marriage +engagement +family +friend +brother +sister +mother +father +parent +child +baby +grandparent +grandmother +grandfather +uncle +aunt +cousin +nephew +niece +relative +neighbor +colleague +boss +manager +team +meeting +job +career +profession +occupation +work +office +company +business +entrepreneur +startup +enterprise +organization +government +law +order +policy +rule +regulation +constitution +right +freedom +justice +court +judge +lawyer +police +criminal +crime +detective +investigation +prison +jail +hospital +doctor +nurse +patient +medicine +treatment +surgery +operation +health +disease +illness +infection +virus +bacteria +vaccine +immunity +nutrition +diet +exercise +fitness +gym +sports +game +football +soccer +basketball +tennis +cricket +hockey +baseball +golf +swimming +cycling +running +race +competition +tournament +champion +winner +victory +defeat +loss +draw +teamwork +strategy +skill +talent +ability +effort +hardwork +success +failure +goal +achievement +dream +ambition +hope +desire +wish +plan +strategy +decision +choice +option +opportunity +risk +challenge +problem +solution +idea +creativity +innovation +invention +discovery +research +development +science +technology +engineering +mathematics +biology +chemistry +physics +astronomy +geography +history +economics +politics +philosophy +psychology +sociology +anthropology +literature +art +painting +sculpture +design +architecture +photography +fashion +style +clothing +shoe +accessory +jewelry +makeup +beauty +care +cosmetic +hair +salon +spa +travel +vacation +holiday +trip +journey +flight +airplane +train +bus +car +taxi +bicycle +boat +ship +ocean +sea +river +lake +mountain +hill +valley +desert +forest +jungle +island +beach +sand +rock +stone +cliff +waterfall From 26c6b870207cf7be7d78d67bce5ecb16e5af0de5 Mon Sep 17 00:00:00 2001 From: ananyag309 Date: Thu, 24 Oct 2024 04:36:51 +0000 Subject: [PATCH 2/2] updating Project-Structure.md --- Project-Structure.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Project-Structure.md b/Project-Structure.md index af2f1d42..037e2b23 100644 --- a/Project-Structure.md +++ b/Project-Structure.md @@ -228,6 +228,8 @@ * [App](Beginner_Projects/Research-Snap/app.py) * Skillsync * [App](Beginner_Projects/SkillSync/app.py) + * Spell Checker + * [Spell Checker](Beginner_Projects/Spell%20Checker/spell_checker.py) * Stock App * [Server](Beginner_Projects/Stock%20App/server.py) * Sudoku Solver