From d157dc7ccfcbd6de2fe520ed4e2eb4f6ec2410e1 Mon Sep 17 00:00:00 2001 From: Rolland306 Date: Tue, 26 Sep 2023 11:23:14 -0400 Subject: [PATCH 1/5] Chose dictionary.py to start. --- Dice-Simulator/dice.py | 4 ++- Dictionary-App/dictionary.py | 62 +++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/Dice-Simulator/dice.py b/Dice-Simulator/dice.py index 798e30dd..ab01b786 100644 --- a/Dice-Simulator/dice.py +++ b/Dice-Simulator/dice.py @@ -1,9 +1,11 @@ import random # also do with numpy (from numpy import random) +"""i can have a board function which prints the board since its being repeated every time. +or include real animations""" # ------------ function definition -def roll_dice(): +def roll_dice(): number = random.randint(1,6) if number == 1: print("-----------") diff --git a/Dictionary-App/dictionary.py b/Dictionary-App/dictionary.py index e9be8faa..526648a7 100644 --- a/Dictionary-App/dictionary.py +++ b/Dictionary-App/dictionary.py @@ -31,35 +31,39 @@ def menu(): return choice - -while(True): - word = input("\nEnter a word: ") - user_choice = menu() - match user_choice: - case 0: - print("Dictionary is closed") - exit(0) - case 1: - meaning = check_meaning(word) - print(meaning) - case 2: - antonym = get_antonym(word) - print(antonym) - case 3: - synonym = get_synonym(word) - print(synonym) - case 4: - print('''Enter a language code in which you want to translate word -Like for URDU language code is ur -For ARABIC language code is ar -For HINDI language code is hi -''') - - lang_choice = input("Enter your choice: ") - trans = translate(word, lang_choice) - print(trans) - case _: - print("Invalid choice!") +# put a main function here +def main(): + while(True): + word = input("\nEnter a word: ") + user_choice = menu() + match user_choice: + case 0: + print("Dictionary is closed") + exit(0) + case 1: + meaning = check_meaning(word) + print(meaning) + case 2: + antonym = get_antonym(word) + print(antonym) + case 3: + synonym = get_synonym(word) + print(synonym) + case 4: + print('''Enter a language code in which you want to translate word + Like for URDU language code is ur + For ARABIC language code is ar + For HINDI language code is hi + ''') + + lang_choice = input("Enter your choice: ") + trans = translate(word, lang_choice) + print(trans) + case _: + print("Invalid choice!") + +if __name__ == "__main__": + main() #------------------------------------------------------------- From 704567ed6979920bf6619040a6ceb7a1066050c5 Mon Sep 17 00:00:00 2001 From: Rolland306 Date: Tue, 26 Sep 2023 23:30:24 -0400 Subject: [PATCH 2/5] initialized dictionary GUI application --- Dictionary-App/dictionaryGUI.py | 73 +++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Dictionary-App/dictionaryGUI.py diff --git a/Dictionary-App/dictionaryGUI.py b/Dictionary-App/dictionaryGUI.py new file mode 100644 index 00000000..ccbcf092 --- /dev/null +++ b/Dictionary-App/dictionaryGUI.py @@ -0,0 +1,73 @@ +import tkinter as tk +from tkinter import * + +# creating main tkinter window +mainWindow = tk.Tk() +mainWindow.title('Dictionary') +mainWindow.geometry("600x400") + +#search button +global response + +# on button press trigger response +def displayResponse(): + response="response is here" + return response + + +searchBtn = Button(mainWindow, text = "Search",padx=5, command= displayResponse()) +searchBtn.grid(row=1, column=0,sticky=W,pady=2,padx=20) + +# checkbox widget +antonyms = Checkbutton(mainWindow, text = "Antonyms") +antonyms.grid(row = 3, column = 0, sticky = W, columnspan = 2) + +synonyms = Checkbutton(mainWindow, text = "Synonyms") +synonyms.grid(row = 4, column = 0, sticky = W, columnspan = 2) + +# translation dropdown menu +translation = Checkbutton(mainWindow, text = "translationDropdown") +translation.grid(row = 5, column = 0, sticky = W, columnspan = 2) + + + + +# Function to handle the Entry widget focus events +def on_entry_focus_in(event): + if entry.get() == placeholder_text: + entry.delete(0, tk.END) + entry.configure(show="") + entry.configure(fg="black") + +def on_entry_focus_out(event): + if entry.get() == "": + entry.delete(0, tk.END) # Clear the entry if it's empty + entry.insert(0, placeholder_text) + entry.configure(show="") + entry.configure(fg="gray") + + +# Create an Entry widget with placeholder text +placeholder_text = "Enter your input.." +#entry widgets used to take user entry +entry = Entry(mainWindow, fg="gray") +entry.insert(0, placeholder_text) +entry.bind("", on_entry_focus_in) +entry.bind("", on_entry_focus_out) + +#arranging entry widgets +entry.grid(row=0, column=0, pady=10, padx=20) + + + +# response on right pane +response = Label(mainWindow, text = "showResponse()" ,padx=5) +response.grid(row=0,column=6, sticky=W, padx=5,pady=2) + + + + + + +# infinite loop which can be terminated by keyboard or mouse interrupt +mainWindow.mainloop() \ No newline at end of file From f546f57f68f9b620eae1a42be4253482f50dc15e Mon Sep 17 00:00:00 2001 From: Rolland306 Date: Fri, 29 Sep 2023 12:07:06 -0400 Subject: [PATCH 3/5] added the gui platform --- Dictionary-App/dictionaryGUI.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Dictionary-App/dictionaryGUI.py b/Dictionary-App/dictionaryGUI.py index ccbcf092..3887fb6c 100644 --- a/Dictionary-App/dictionaryGUI.py +++ b/Dictionary-App/dictionaryGUI.py @@ -7,12 +7,13 @@ mainWindow.geometry("600x400") #search button -global response +global results +results = " " # on button press trigger response def displayResponse(): - response="response is here" - return response + results="response is here" + return results searchBtn = Button(mainWindow, text = "Search",padx=5, command= displayResponse()) @@ -59,9 +60,11 @@ def on_entry_focus_out(event): entry.grid(row=0, column=0, pady=10, padx=20) +# TODO Dynamically update the results variable based on search results, and display it on the right pane +# TODO add a bottom border, and show results based on the checkboxes, and translation dropdown menu # response on right pane -response = Label(mainWindow, text = "showResponse()" ,padx=5) +response = Label(mainWindow, text = results ,padx=5) response.grid(row=0,column=6, sticky=W, padx=5,pady=2) From bf080408d6ce8c5bbca7a69f093a0f4409323577 Mon Sep 17 00:00:00 2001 From: Rolland306 Date: Wed, 18 Oct 2023 16:12:14 -0400 Subject: [PATCH 4/5] Dictionary GUI implementation --- Dictionary-App/dictionaryGUI.py | 170 ++++++++++++++++++++------------ 1 file changed, 106 insertions(+), 64 deletions(-) diff --git a/Dictionary-App/dictionaryGUI.py b/Dictionary-App/dictionaryGUI.py index 3887fb6c..7363e163 100644 --- a/Dictionary-App/dictionaryGUI.py +++ b/Dictionary-App/dictionaryGUI.py @@ -1,76 +1,118 @@ import tkinter as tk from tkinter import * - -# creating main tkinter window +from PyDictionary import PyDictionary + +dictionary = PyDictionary() + +# Function to check the meaning of a word +def check_meaning(word): + meaning = dictionary.meaning(word) + if meaning: + return "\n".join([f"{part}: {', '.join(definitions)}" for part, definitions in meaning.items()]) + else: + return "Meaning not found." + +# Function to get antonyms of a word +def get_antonym(word): + antonyms = dictionary.antonym(word) + if antonyms: + return ", ".join(antonyms) + else: + return "Antonyms not found." + +# Function to get synonyms of a word +def get_synonym(word): + synonyms = dictionary.synonym(word) + if synonyms: + return ", ".join(synonyms) + else: + return "Synonyms not found." + +# Function to translate a word to another language +def translate(word, language): + translation = dictionary.translate(word, language) + if translation: + return translation + else: + return f"Translation to {language} not found." + +# Function to update the response based on checkbox and dropdown selections +def update_response(): + selected_word = entry.get() + meaning_text.delete(1.0, tk.END) # Clear previous meaning + results_text.delete(1.0, tk.END) # Clear previous results + if selected_word: + meaning = check_meaning(selected_word) + meaning_text.insert(tk.END, f"Meaning:\n{meaning}\n") + + if antonyms_var.get(): + antonyms = get_antonym(selected_word) + results_text.insert(tk.END, f"Antonyms: {antonyms}\n") + + if synonyms_var.get(): + synonyms = get_synonym(selected_word) + results_text.insert(tk.END, f"Synonyms: {synonyms}\n") + + if translation_var.get(): + lang_choice = translation_var.get() + trans = translate(selected_word, lang_choice) + results_text.insert(tk.END, f"Translation ({lang_choice}): {trans}\n") + +# Function to display the initial meaning +def display_initial_meaning(event): + selected_word = entry.get() + meaning_text.delete(1.0, tk.END) # Clear previous meaning + if selected_word: + meaning = check_meaning(selected_word) + meaning_text.insert(tk.END, f"Meaning:\n{meaning}\n") + +# Creating main tkinter window mainWindow = tk.Tk() mainWindow.title('Dictionary') -mainWindow.geometry("600x400") - -#search button -global results -results = " " - -# on button press trigger response -def displayResponse(): - results="response is here" - return results - - -searchBtn = Button(mainWindow, text = "Search",padx=5, command= displayResponse()) -searchBtn.grid(row=1, column=0,sticky=W,pady=2,padx=20) +mainWindow.geometry("800x500") -# checkbox widget -antonyms = Checkbutton(mainWindow, text = "Antonyms") -antonyms.grid(row = 3, column = 0, sticky = W, columnspan = 2) +# Checkbox widgets +antonyms_var = tk.BooleanVar() +antonyms = Checkbutton(mainWindow, text="Antonyms", variable=antonyms_var) +antonyms.grid(row=3, column=0, sticky=W, columnspan=2,padx=20) -synonyms = Checkbutton(mainWindow, text = "Synonyms") -synonyms.grid(row = 4, column = 0, sticky = W, columnspan = 2) +synonyms_var = tk.BooleanVar() +synonyms = Checkbutton(mainWindow, text="Synonyms", variable=synonyms_var) +synonyms.grid(row=4, column=0, sticky=W, columnspan=2,padx=20) -# translation dropdown menu -translation = Checkbutton(mainWindow, text = "translationDropdown") -translation.grid(row = 5, column = 0, sticky = W, columnspan = 2) +# Label for the Translation dropdown menu +translation_label = Label(mainWindow, text="Translation:") +translation_label.grid(row=5, column=0, sticky=W, padx=20) +# Translation dropdown menu +languages = ["","ur", "ar", "hi"] # Add your language codes here +translation_var = tk.StringVar() +translation_var.set(languages[0]) # Set the default language +translation_menu = OptionMenu(mainWindow, translation_var, *languages) +translation_menu.grid(row=5, column=1, sticky=W) - -# Function to handle the Entry widget focus events -def on_entry_focus_in(event): - if entry.get() == placeholder_text: - entry.delete(0, tk.END) - entry.configure(show="") - entry.configure(fg="black") - -def on_entry_focus_out(event): - if entry.get() == "": - entry.delete(0, tk.END) # Clear the entry if it's empty - entry.insert(0, placeholder_text) - entry.configure(show="") - entry.configure(fg="gray") - - -# Create an Entry widget with placeholder text -placeholder_text = "Enter your input.." -#entry widgets used to take user entry +# Entry widget with placeholder text +placeholder_text = "" entry = Entry(mainWindow, fg="gray") entry.insert(0, placeholder_text) -entry.bind("", on_entry_focus_in) -entry.bind("", on_entry_focus_out) - -#arranging entry widgets -entry.grid(row=0, column=0, pady=10, padx=20) - - -# TODO Dynamically update the results variable based on search results, and display it on the right pane -# TODO add a bottom border, and show results based on the checkboxes, and translation dropdown menu - -# response on right pane -response = Label(mainWindow, text = results ,padx=5) -response.grid(row=0,column=6, sticky=W, padx=5,pady=2) - - - - - - -# infinite loop which can be terminated by keyboard or mouse interrupt -mainWindow.mainloop() \ No newline at end of file +entry.bind("", display_initial_meaning) +entry.bind("", display_initial_meaning) +entry.grid(row=0, column=0,sticky=W, pady=10, padx=20) + +# Text widget for displaying meaning +meaning_text = Text(mainWindow, height=10, width=40) +meaning_text.grid(column=0, columnspan=2, padx=20, pady=10) + +# Text widget for displaying results +results_text = Text(mainWindow, height=10, width=40) +results_text.grid(row=6, column=6, columnspan=2, padx=20, pady=10) + +# Search button +def display_response(): + update_response() +searchBtn = Button(mainWindow, text="Search", padx=5, command=display_response) +searchBtn.grid(row=1, column=0, sticky=W, pady=2, padx=20) + +# Infinite loop which can be terminated by keyboard or mouse interrupt +mainWindow.mainloop() From 59fc1cf27cb7c508e77ed57182a5beb4b39f6f41 Mon Sep 17 00:00:00 2001 From: Rolland306 Date: Wed, 18 Oct 2023 16:16:22 -0400 Subject: [PATCH 5/5] important revisions --- Dice-Simulator/dice.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dice-Simulator/dice.py b/Dice-Simulator/dice.py index ab01b786..64a5c49c 100644 --- a/Dice-Simulator/dice.py +++ b/Dice-Simulator/dice.py @@ -1,7 +1,5 @@ import random # also do with numpy (from numpy import random) -"""i can have a board function which prints the board since its being repeated every time. -or include real animations""" # ------------ function definition