-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictionaryGUI.py
52 lines (40 loc) · 1.47 KB
/
dictionaryGUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import json
from tkinter import *
from tkinter.messagebox import showinfo,askquestion
from difflib import get_close_matches
data = json.load(open("data.json"))
win = Tk()
win.title("Online Dictionary")
win.geometry('300x150')
def translate():
word=entry.get()
word = word.lower()
if word in data:
meanings = data[word]
elif word.title() in data:
meanings = data[word.title()]
elif word.upper() in data:
meanings = data[word.upper()]
elif len(get_close_matches(word,data.keys())) > 0:
decide = askquestion("Meanings:-","\nHey, Did you mean '%s' instead ?" %get_close_matches(word,data.keys())[0],icon="info")
if decide == "yes":
meanings = data[get_close_matches(word,data.keys())[0]]
else :
showinfo("OOPS","Then, Buddy you have entered a wrong word please check it again!!!\n")
else:
showinfo( "OOPS","That's not a correct word please check it again!!!\n")
if type(meanings)==list:
index=1
result=""
for meaning in meanings:
result+=( str(index) + ". " + meaning)
index+=1
result+="\n\n"
showinfo("\nMeanings:-",result)
label=Label(win,text="Enter Your Word:- ")
label.grid(row=2,column=1)
entry = Entry(win)
entry.grid(row=2,column=5)
button=Button(win,text="Search",command=translate)
button.grid(row=3,column=5)
win.mainloop()