-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiveDict_v1.py
122 lines (98 loc) · 3.47 KB
/
LiveDict_v1.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from tkinter import *
import tkinter.messagebox
from PyDictionary import PyDictionary
root=Tk()
root.title("Live Dictionary (Yagnesh Vakharia)")
root.config(bg='light blue')
root.resizable(width=False, height=False)
pyDict=PyDictionary()
radioVar=IntVar()
usrInput=StringVar()
def layout():
#Menu bar for File cascade and About command...
menuBar=Menu(root)
fileMenu=Menu(menuBar,tearoff=0)
fileMenu.add_command(label="Save",command=save)
fileMenu.add_separator()
fileMenu.add_command(label="Exit",command=ex)
menuBar.add_cascade(label="File", menu=fileMenu)
#About command
menuBar.add_command(label="About",command=about)
#radio buttons
dictRadio=Radiobutton(root,text="Dictionary",variable=radioVar,value=1)
antoRadio=Radiobutton(root,text="Antonyms",variable=radioVar,value=2)
synoRadio=Radiobutton(root,text="Synonyms",variable=radioVar,value=3)
#Search box & bar
searchBox=Entry(root,width=30,textvariable=usrInput,bg="#f9e0e8")
searchBar=Button(root,text="Search",width=15,command=search,bg="white")
#results
scrollbar = Scrollbar(root)
scrollbar.grid(sticky=N+S+W,column=4,row=3,rowspan=3)
global results
results=Text(root,height=7,width=30,wrap=WORD,yscrollcommand=scrollbar.set,bg="#f9e0e8")
#positions
dictRadio.grid(row=0,column=0,padx=5,pady=5)
antoRadio.grid(row=0,column=1,padx=5,pady=5)
synoRadio.grid(row=0,column=2,padx=5,pady=5)
searchBox.grid(row=1,columnspan=3,ipady=5,pady=10,sticky=S)
searchBar.grid(row=2,columnspan=3,sticky=N)
results.grid(row=3,columnspan=3,pady=10,padx=5)
scrollbar.config(command=results.yview)
#end
root.config(menu=menuBar)
root.mainloop()
#conditional function calling
def search():
if radioVar.get()==1:
dictSearch()
elif radioVar.get()==2:
antoSearch()
else:
synoSearch()
#dictionary search function
def dictSearch():
if pyDict.meaning(usrInput.get())==None:
results.delete(1.0,END)
results.insert(END,"Sorry the word has no such meanings")
else:
results.delete(1.0,END)
for i in pyDict.meaning(usrInput.get()):
results.insert(END,i)
results.insert(END,"\n"+pyDict.meaning(usrInput.get())[i][0]+"\n"+"-"*30+"\n")
#antonym search function
def antoSearch():
if pyDict.antonym(usrInput.get())==None:
results.delete(1.0,END)
results.insert(END,"Sorry the word has no such antonyms")
else:
num=1
results.delete(1.0,END)
for i in pyDict.antonym(usrInput.get()):
results.insert(END,"\n"+str(num)+") "+i+"\n")
num=int(num)+1
#synonym search function
def synoSearch():
if pyDict.synonym(usrInput.get())==None:
results.delete(1.0,END)
results.insert(END,"Sorry the word has no such synonyms")
else:
num=1
results.delete(1.0,END)
for i in pyDict.synonym(usrInput.get()):
results.insert(END,"\n"+str(num)+") "+i+"\n")
num=int(num)+1
#save function
def save():
try:
f=open("dict_"+usrInput.get()+".txt","w")
f.write(results.get(1.0,END))
f.close()
except Exception:
messagebox.showerror("Error","Something went wrong. Please try again!")
#about function
def about():
tk.messagebox.showinfo("About","This program is created by Yagnesh Vakharia.\nContact: yagneshvakharia97@gmail.com")
#destroying the frame
def ex():
root.destroy()
layout()