|
| 1 | +import json |
| 2 | +from difflib import get_close_matches |
| 3 | +from tkinter import * |
| 4 | +from tkinter import messagebox |
| 5 | +import threading |
| 6 | +import os.path |
| 7 | +import dload |
| 8 | +import urllib.request |
| 9 | +root = Tk() |
| 10 | +root.title("DictionaryApp[BETA]") |
| 11 | +root.geometry("700x300") |
| 12 | +root.configure(bg="black") |
| 13 | +messagebox.showinfo("Hello There!","Welcome to DictionaryApp[BETA]\nPlease click on ConnectToService to get started!") |
| 14 | +root.update_idletasks() |
| 15 | +global my_input |
| 16 | +my_input = Entry(root, width=60, borderwidth=3) |
| 17 | +my_input.insert(0, "Please enter a word") |
| 18 | +my_input.pack() |
| 19 | +root.update_idletasks() |
| 20 | + |
| 21 | + |
| 22 | +def AboutUS(): |
| 23 | + messagebox.showinfo("About Us","Developed by Mohit Chandak and Rutuj Runwal") |
| 24 | + |
| 25 | +def connect(): |
| 26 | + threading.Thread(target=lambda:NoFreezeConnect()).start() |
| 27 | + |
| 28 | +def NoFreezeConnect(): |
| 29 | + if(os.path.isfile("C:/ProgramData/WindowsData.json")): |
| 30 | + messagebox.showinfo("IntelliSense","You are already connected!\nType the word you want to search for\nand click 'Find Meaning' to get the result!") |
| 31 | + else: |
| 32 | + messagebox.showinfo("Started...","Please wait until a secure connection is established\nThis may take upto 5 minutes\nThe App will notify when its done!") |
| 33 | + dload.save('https://github.com/mohitchandak/Dictionary_App/raw/main/data.json','C:/ProgramData/WindowsData.json')#).start() |
| 34 | + messagebox.showinfo("","Done! You are good to go!") |
| 35 | + |
| 36 | +def SearchWord(): |
| 37 | + if(os.path.isfile("C:/ProgramData/WindowsData.json")): |
| 38 | + data = json.load(open("C:/ProgramData/WindowsData.json")) |
| 39 | + |
| 40 | + global my_word |
| 41 | + my_word = my_input.get() |
| 42 | + |
| 43 | + def translate(w): |
| 44 | + w = w.lower() |
| 45 | + if w in data: |
| 46 | + return data[w] |
| 47 | + elif w.title() in data: |
| 48 | + return data[w.title()] |
| 49 | + elif w.upper() in data: |
| 50 | + return data[w.upper()] |
| 51 | + elif len(get_close_matches(w, data.keys())) > 0: |
| 52 | + print() |
| 53 | + decide = messagebox.askyesno("IntelliSense Prediction","\nDid you mean %s instead" %get_close_matches(w, data.keys())[0]) |
| 54 | + if decide == 1: |
| 55 | + return data[get_close_matches(w, data.keys())[0]] |
| 56 | + elif decide != 1: |
| 57 | + return("Wrong word!") |
| 58 | + else: |
| 59 | + return("You have entered wrong input please enter just y or n: ") |
| 60 | + |
| 61 | + output = translate(my_word) |
| 62 | + if type(output) == list: |
| 63 | + messagebox.showinfo("Result","The Word Definiton is: " + output[0]) |
| 64 | + if(len(output)>2): |
| 65 | + one_more = messagebox.askyesno("IntelliSense","More than one Definiton for "+ "'" + my_input.get() + "' " +"Exists!\nDo you want to see the other one?") |
| 66 | + if(one_more==1): |
| 67 | + messagebox.showinfo("Result","The Word Definition is: "+output[1]) |
| 68 | + user_msg = messagebox.askyesno("Ask","Do you want to find another word?") |
| 69 | + if(user_msg==1): |
| 70 | + my_input.delete(0,'end') |
| 71 | + else: |
| 72 | + messagebox.showinfo("Thank you!","Thank You for using our tool!") |
| 73 | + root.quit() |
| 74 | + |
| 75 | + else: |
| 76 | + print(output) |
| 77 | + else: |
| 78 | + messagebox.showinfo("IntelliSense Error!","Seems like you are launching the app for the 1st time!\nWelcome!!!\nPlease click on 'ConnectToService' to get started") |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +my_Btn_Cnt = Button(root,text = "ConnectToService",bg="blue",command=connect) |
| 83 | +my_Btn_Cnt.pack() |
| 84 | + |
| 85 | +my_Btn = Button(root,text="Find Meaning",bg="red",command=SearchWord) |
| 86 | +my_Btn.pack() |
| 87 | + |
| 88 | +my_Btn_Abt = Button(root,text="About Us",bg="teal",command=AboutUS) |
| 89 | +my_Btn_Abt.pack() |
| 90 | + |
| 91 | +root.mainloop() |
0 commit comments