diff --git a/Beginner_Projects/Morse Code Translator with GUI/README.md b/Beginner_Projects/Morse Code Translator with GUI/README.md new file mode 100644 index 00000000..10f1a05e --- /dev/null +++ b/Beginner_Projects/Morse Code Translator with GUI/README.md @@ -0,0 +1,49 @@ +## **Morse Code Translator GUI** + +### ๐ŸŽฏ **Goal** + +The main goal of this project is to provide a simple, user-friendly tool to translate text between English and Morse code, facilitating quick and efficient communication for learning, teaching, or decoding purposes. + +### ๐Ÿงต **Dataset** + +No specific dataset is used in this project as it operates based on a predefined dictionary of Morse code mappings for the English alphabet, numerals, and common symbols. + +### ๐Ÿงพ **Description** + +This project is a GUI-based application that allows users to easily convert between English and Morse code using a clean and intuitive interface. Built with Python and Tkinter, it provides both encoding (English to Morse) and decoding (Morse to English) functionality, supporting a variety of characters and symbols. The translator is designed for anyone interested in learning Morse code or performing translations between the two languages. + +### ๐Ÿงฎ **What I had done!** + +1. Designed a simple GUI interface using Tkinter for seamless user interaction. +2. Implemented two-way translation between English text and Morse code. +3. Added functionality to clear the input and output fields. +4. Provided error handling for invalid selections and inputs. +5. Supported a wide range of characters, including letters, numbers, and symbols. +6. Developed logic to handle Morse code input and convert it back to English text. +7. Optimized the process for easy real-time conversion with just one click. + +### ๐Ÿš€ **Models Implemented** + +This project does not use machine learning algorithms or models, as the translation is achieved using a predefined dictionary of Morse code. The chosen method of direct mapping between characters and Morse symbols ensures efficiency and accuracy for this specific task. + +### ๐Ÿ“š **Libraries Needed** + +- `Tkinter` for creating the GUI interface. +- `messagebox` from Tkinter for displaying error messages. + +### ๐Ÿ“Š **Exploratory Data Analysis Results** + +Since the project does not involve a dataset or statistical analysis, there are no EDA results to display. + +### ๐Ÿ“ˆ **Performance of the Models based on the Accuracy Scores** + +This project does not rely on machine learning models, and hence, there are no accuracy scores to report. The translation between English and Morse code is achieved through direct mapping, ensuring 100% accuracy for valid input. + +### ๐Ÿ“ข **Conclusion** + +This Morse Code Translator GUI offers a simple, efficient tool for translating text between English and Morse code. It serves as an educational tool or utility for decoding and encoding Morse code, ensuring quick conversions. The user-friendly interface makes it accessible to users of all experience levels, and the translation logic ensures reliable and accurate output. + +### โœ’๏ธ **Your Signature** + +**Aviral Garg** +[GitHub](https://github.com/aviralgarg05) | [LinkedIn](https://www.linkedin.com/in/aviralgarg05) diff --git a/Beginner_Projects/Morse Code Translator with GUI/main.py b/Beginner_Projects/Morse Code Translator with GUI/main.py new file mode 100644 index 00000000..610e14fa --- /dev/null +++ b/Beginner_Projects/Morse Code Translator with GUI/main.py @@ -0,0 +1,161 @@ +# Import Tkinter module +from tkinter import * +from tkinter import messagebox + +# Create a window +root = Tk() + +# Create global variables +variable1 = StringVar(root) +variable2 = StringVar(root) + +# Initialise the variables +variable1.set("Language select") +variable2.set("Language select") + +""" +VARIABLE KEY +'cipher' -> 'stores the morse translated form of the english string' +'decipher' -> 'stores the english translated form of the morse string' +'citext' -> 'stores morse code of a single character' +'i' -> 'keeps count of the spaces between morse characters' +'message' -> 'stores the string to be encoded or decoded' +""" + +# Dictionary representing the morse code chart +MORSE_CODE_DICT = { + "A": ".-", "B": "-...", "C": "-.-.", "D": "-..", "E": ".", "F": "..-.", + "G": "--.", "H": "....", "I": "..", "J": ".---", "K": "-.-", "L": ".-..", + "M": "--", "N": "-.", "O": "---", "P": ".--.", "Q": "--.-", "R": ".-.", + "S": "...", "T": "-", "U": "..-", "V": "...-", "W": ".--", "X": "-..-", + "Y": "-.--", "Z": "--..", "1": ".----", "2": "..---", "3": "...--", + "4": "....-", "5": ".....", "6": "-....", "7": "--...", "8": "---..", + "9": "----.", "0": "-----", ", ": "--..--", ".": ".-.-.-", "?": "..--..", + "/": "-..-.", "-": "-....-", "(": "-.--.", ")": "-.--.-", "!": "-.-.--", + "&": ".-...", ":": "---...", ";": "-.-.-.", "=": "-...-", "+": ".-.-.", + "_": "..--.-", "\"": ".-..-.", "$": "...-..-", "@": ".--.-." +} + +# Function to clear both the text areas +def clearAll(): + # whole content of text area is deleted + language1_field.delete(1.0, END) + language2_field.delete(1.0, END) + +# Function to perform conversion from one language to another +def convert(): + # get a whole input content from text box ignoring \n from the text box content + message = language1_field.get("1.0", "end")[:-1] + + # get the content from variable1 and 2, check their values + if variable1.get() == variable2.get(): + # show the error message + messagebox.showerror("Can't Be same Language") + return + + elif variable1.get() == "English" and variable2.get() == "Morse Code": + # function call for encryption + rslt = encrypt(message) + + elif variable1.get() == "Morse Code" and variable2.get() == "English": + # function call for decryption + rslt = decrypt(message) + + else: + # show the error message + messagebox.showerror("please choose valid language code..") + return + + # insert content into text area from rslt variable + language2_field.delete(1.0, END) + language2_field.insert("end -1 chars", rslt) + +# Function to encrypt the string according to the morse code chart +def encrypt(message): + cipher = "" + for letter in message: + if letter.isalpha(): + cipher += MORSE_CODE_DICT[letter.upper()] + " " + elif letter != " ": + # Looks up the dictionary and adds the corresponding morse code + cipher += MORSE_CODE_DICT[letter] + " " + else: + # 1 space indicates different characters, 2 spaces indicate different words + cipher += " " + return cipher + +# Function to decrypt the string from morse to english +def decrypt(message): + # extra space added at the end to access the last morse code + message += " " + decipher = "" + citext = "" + for letter in message: + # checks for space + if letter != " ": + # counter to keep track of space + i = 0 + # storing morse code of a single character + citext += letter + else: + # if i = 1 that indicates a new character + i += 1 + if i == 2: + # adding space to separate words + decipher += " " + else: + # accessing the keys using their values (reverse of encryption) + decipher += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT.values()).index(citext)] + citext = "" + return decipher + +# Driver code +if __name__ == "__main__": + # Set the background colour of GUI window + root.configure() + + # Set the configuration of GUI window (WidthxHeight) + root.geometry("450x400") + + # set the name of tkinter GUI window + root.title("Morse Code Translator") + + # Create Welcome to Morse Code Translator label + headlabel = Label(root, text="Welcome to Morse Code Translator", fg="black", justify="center") + + # Create labels for input and conversion fields + label1 = Label(root, text="First Language : Input", fg="black") + label2 = Label(root, text="Second Language : To Convert", fg="black") + + # grid method is used for placing widgets at respective positions + headlabel.grid(row=0, column=1) + label1.grid(row=2, column=0) + label2.grid(row=3, column=0) + + # Create text area boxes for input and output + language1_field = Text(root, height=5, width=25, font="lucida 13") + language2_field = Text(root, height=5, width=25, font="lucida 13") + + # padx keyword argument used to set padding along x-axis + language1_field.grid(row=1, column=1, padx=10) + language2_field.grid(row=5, column=1, padx=10) + + # list of language codes + languageCode_list = ["English", "Morse Code"] + + # create drop down menus for selecting languages + FromLanguage_option = OptionMenu(root, variable1, *languageCode_list) + ToLanguage_option = OptionMenu(root, variable2, *languageCode_list) + + FromLanguage_option.grid(row=2, column=1, ipadx=10) + ToLanguage_option.grid(row=3, column=1, ipadx=10) + + # Create buttons for Convert and Clear functionalities + button1 = Button(root, text="Convert", bg="gray", fg="black", command=convert, cursor="hand2") + button1.grid(row=4, column=1) + + button2 = Button(root, text="Clear", bg="red", fg="black", command=clearAll, padx=10, cursor="hand2") + button2.grid(row=6, column=1) + + # Start the GUI + root.mainloop() diff --git a/Beginner_Projects/Morse Code Translator with GUI/screenshots/tkinter-working.gif b/Beginner_Projects/Morse Code Translator with GUI/screenshots/tkinter-working.gif new file mode 100644 index 00000000..918c4d7e Binary files /dev/null and b/Beginner_Projects/Morse Code Translator with GUI/screenshots/tkinter-working.gif differ diff --git a/README.md b/README.md index be7dd5b1..2938580e 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,11 @@ The PyVerse repository is organized as follows: โ”‚ โ””โ”€โ”€ stack.py โ”œโ”€โ”€ Automation_Tools โ”œโ”€โ”€ Beginner_Projects +โ”‚ โ”œโ”€โ”€ Morse Code Translator with GUI +โ”‚ โ”‚ โ”œโ”€โ”€ README.md +โ”‚ โ”‚ โ”œโ”€โ”€ main.py +โ”‚ โ”‚ โ””โ”€โ”€ screenshots +โ”‚ โ”‚ โ””โ”€โ”€ tkinter-working.gif โ”‚ โ””โ”€โ”€ Stock App โ”‚ โ”œโ”€โ”€ Readme.md โ”‚ โ”œโ”€โ”€ Templates diff --git a/repo_structure.txt b/repo_structure.txt index fe521301..cec47001 100644 --- a/repo_structure.txt +++ b/repo_structure.txt @@ -13,6 +13,11 @@ โ”‚ โ””โ”€โ”€ stack.py โ”œโ”€โ”€ Automation_Tools โ”œโ”€โ”€ Beginner_Projects +โ”‚ โ”œโ”€โ”€ Morse Code Translator with GUI +โ”‚ โ”‚ โ”œโ”€โ”€ README.md +โ”‚ โ”‚ โ”œโ”€โ”€ main.py +โ”‚ โ”‚ โ””โ”€โ”€ screenshots +โ”‚ โ”‚ โ””โ”€โ”€ tkinter-working.gif โ”‚ โ””โ”€โ”€ Stock App โ”‚ โ”œโ”€โ”€ Readme.md โ”‚ โ”œโ”€โ”€ Templates