-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.py
More file actions
187 lines (146 loc) · 5.16 KB
/
dictionary.py
File metadata and controls
187 lines (146 loc) · 5.16 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
"""
Created on Thu Apr 6 21:19:48 2020
@author: kushagar
"""
# using wordnet as set of words
from nltk.corpus import wordnet
from tkinter import *
def finder():
try:
global e
global string
global he
global root
global antonyms
string = e.get()
syns = wordnet.synsets(string)
he = [wd.lemmas()[0].name() for wd in syns]
he = list(set(he))
antonyms = []
for syn in wordnet.synsets(string):
for l in syn.lemmas():
if l.antonyms():
antonyms.append(l.antonyms()[0].name())
antonyms = list(set(antonyms))
#pane for synonyms
pane2a = Frame(root)
pane2a.pack(fill = BOTH, expand = True)
pane2a.configure(bg='#A3E4D7')
#pane for antonyms
pane2b = Frame(root)
pane2b.pack(fill = BOTH, expand = True)
pane2b.configure(bg='#A3E4D7')
#pane for output lables
pane3 = Frame(root)
pane3.pack(fill = BOTH, expand = True)
pane3.configure(bg='#A3E4D7')
#Synonyms
Label(pane2a, text="Synonyms",bg='#A3E4D7').pack()
for i in range(len(he)):
i = Button(pane2a,text=he[i],command=lambda j=i: printtext(j,pane2a,pane2b))
i.pack(side='left',pady=10,padx=2)
i.configure(bg='#76D7C4')
#Antonyms
Label(pane2b, text="Antonyms",bg = '#A3E4D7').pack()
for p in range(len(antonyms)):
p = Button(pane2b,text=antonyms[p],command=lambda q=p: printtextt(q,pane2b,pane2a))
p.pack(side='left',pady=10,padx=2)
p.configure(bg='#76D7C4')
#Output lables
Label(pane3, text="Word: "+string.upper(),bg='#A3E4D7',font='helvetica').pack()
Label(pane3, text="Definition: "+syns[0].definition(),bg='#A3E4D7').pack()
Label(pane3, text="Examples: "+syns[0].examples()[0],bg='#A3E4D7').pack()
Label(pane3, text=" "+syns[0].examples()[0],bg='#A3E4D7').pack()
Label(pane3,text="------------------------------------------------------------------------------------------------------",bg='#A3E4D7').pack()
except:
Label(pane3, text="No result Found",bg='#A3E4D7').pack()
Label(pane3,text="-----------------------------------------------------------------------------------------------------",bg='#A3E4D7').pack()
#Called by Synonyms
def printtext(i,pane,panee):
global e
e.delete(0,END)
e.insert(0,he[i])
pane.destroy()
panee.destroy()
finder()
#called by antonyms
def printtextt(i,pane,panee):
global e
e.delete(0,END)
e.insert(0,antonyms[i])
pane.destroy()
panee.destroy()
finder()
#To clear the window
def clear():
global root
root.destroy()
root = Tk()
root.title('Dictionary')
pane = Frame(root)
pane.configure(bg='#A3E4D7')
pane.pack(fill = BOTH, expand = True)
pane1 = Frame(root)
pane1.pack(fill = BOTH, expand = True)
pane1.configure(bg='#A3E4D7')
Label(pane, text='Enter the word',bg='#A3E4D7',font='helvetica').pack(side='left')
e = Entry(pane)
e.pack(side='left',padx=20,pady=10)
e.configure(bg='#E8F8F5')
m1 = Button(pane,text='Clear',command=clear)
m1.pack(side='right')
m1.configure(bg='#76D7C4')
m2 = Button(pane,text='New',command=new)
m2.pack(side='right',padx=10)
m2.configure(bg='#76D7C4')
m = Button(pane1,text='Search',command=finder)
m.pack(side='left',padx=10)
m.configure(bg='#76D7C4')
root.mainloop()
#To open another fresh window
def new():
global root
root = Tk()
root.title('Dictionary')
pane = Frame(root)
pane.configure(bg='#A3E4D7')
pane.pack(fill = BOTH, expand = True)
pane1 = Frame(root)
pane1.pack(fill = BOTH, expand = True)
pane1.configure(bg='#A3E4D7')
Label(pane, text='Enter the word',bg='#A3E4D7',font='helvetica').pack(side='left')
e = Entry(pane)
e.pack(side='left',padx=20,pady=10)
e.configure(bg='#E8F8F5')
m1 = Button(pane,text='Clear',command=clear)
m1.pack(side='right')
m1.configure(bg='#76D7C4')
m2 = Button(pane,text='New',command=new)
m2.pack(side='right',padx=10)
m2.configure(bg='#76D7C4')
m = Button(pane1,text='Search',command=finder)
m.pack(side='left',padx=10)
m.configure(bg='#76D7C4')
root.mainloop()
root = Tk() #starting
root.title('Dictionary')
pane = Frame(root)
pane.configure(bg='#A3E4D7')
pane.pack(fill = BOTH, expand = True)
pane1 = Frame(root)
pane1.pack(fill = BOTH, expand = True)
pane1.configure(bg='#A3E4D7')
Label(pane, text='Enter the word',bg='#A3E4D7',font='helvetica').pack(side='left')
e = Entry(pane)
e.pack(side='left',padx=20,pady=10)
e.configure(bg='#E8F8F5')
m1 = Button(pane,text='Clear',command=clear)
m1.pack(side='right')
m1.configure(bg='#76D7C4')
m2 = Button(pane,text='New',command=new)
m2.pack(side='right',padx=10)
m2.configure(bg='#76D7C4')
m = Button(pane1,text='Search',command=finder)
m.pack(side='left',padx=10)
m.configure(bg='#76D7C4')
root.mainloop()