-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictionary.py
716 lines (614 loc) · 25.9 KB
/
dictionary.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
'''
Following is the code for tkinter GUI based dictionary created in python.
Here for data needed for dictionary, I have used data.json file.
Functions and it's description
clear_text() -> clears the input and output text field
search_word() -> searches meaning for given input word,
-> This function not only searches but also, check the case of
i.) word having multiple meaning
ii.) if word is wrong, prints closest word meaning
iii.) also deal if word is title
# taking integer as speech input -------------------
import speech_recognition as sr
import time
t = {'one':1,'two':2,'three':3,'four':4,'five':5,'six':6,'seven':7,'eight':8,'nine':9,'ten':10}
r = sr.Recognizer()
with sr.Microphone() as source:
print('Speak anything: ')
audio = r.listen(source)
try:
text = r.recognize_google(audio)
print('You said : {0} {1} '.format(text, t[text]))
time.sleep(1)
except:
print('Sorry could not recogonize your voice')
'''
# -----------------------------------------------------------------------------------------------------
import io # used for dealing with input and output
from tkinter import * #importing the necessary libraries
import tkinter.messagebox as mbox
import tkinter as tk # imported tkinter as tk
import json
from difflib import get_close_matches
import pandas as pd
import pyttsx3
import speech_recognition as sr
import re
import pyaudio
# ------------------------------------------------------------------------------------------------------------------
data = pd.read_csv('Related/words.csv')
autocompleteList = data['Words'].tolist()
# -----------------------------------------------------------------------------------------------
class Keypad(tk.Frame):
cells = [
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm','n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M','N', 'O', 'P', 'Q','R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
['!', '@', '#', '$', '%', '&', '*', '/', '\'', '.', ',', ';', ':', '?', '<', '>','😀','😋','😂','🌞','🌴','🍕','🏳', '♻', '✔', '👍'],
]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.target = None
self.memory = ''
for y, row in enumerate(self.cells):
for x, item in enumerate(row):
b = tk.Button(self, text=item, command=lambda text=item:self.append(text),font=("Arial", 14), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
b.grid(row=y, column=x, sticky='news')
x = tk.Button(self, text='Space', command=self.space,font=("Arial", 14), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
x.grid(row=0, column=10, columnspan='4', sticky='news')
x = tk.Button(self, text='tab', command=self.tab,font=("Arial", 14), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
x.grid(row=0, column=14, columnspan='3', sticky='news')
x = tk.Button(self, text='Backspace', command=self.backspace,font=("Arial", 14), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
x.grid(row=0, column=17,columnspan='3', sticky='news')
x = tk.Button(self, text='Clear', command=self.clear,font=("Arial", 14), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
x.grid(row=0, column=20, columnspan='3', sticky='news')
x = tk.Button(self, text='Hide', command=self.hide,font=("Arial", 14), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
x.grid(row=0, column=23, columnspan='3', sticky='news')
def get(self):
if self.target:
return self.target.get()
def append(self, text):
if self.target:
self.target.insert('end', text)
def clear(self):
if self.target:
self.target.delete(0, END)
def backspace(self):
if self.target:
text = self.get()
text = text[:-1]
self.clear()
self.append(text)
def space(self):
if self.target:
text = self.get()
text = text + " "
self.clear()
self.append(text)
def tab(self): # 5 spaces
if self.target:
text = self.get()
text = text + " "
self.clear()
self.append(text)
def copy(self):
#TODO: copy to clipboad
if self.target:
self.memory = self.get()
self.label['text'] = 'memory: ' + self.memory
print(self.memory)
def paste(self):
#TODO: copy from clipboad
if self.target:
self.append(self.memory)
def show(self, entry):
self.target = entry
self.place(relx=0.5, rely=0.5, anchor='c')
def hide(self):
self.target = None
self.place_forget()
#-------------------------------------------------------
class AutocompleteEntry(Entry):
def __init__(self, autocompleteList, *args, **kwargs):
# Listbox length
if 'listboxLength' in kwargs:
self.listboxLength = kwargs['listboxLength']
del kwargs['listboxLength']
else:
self.listboxLength = 10
# Custom matches function
if 'matchesFunction' in kwargs:
self.matchesFunction = kwargs['matchesFunction']
del kwargs['matchesFunction']
else:
def matches(fieldValue, acListEntry):
pattern = re.compile('.*' + re.escape(fieldValue) + '.*', re.IGNORECASE)
return re.match(pattern, acListEntry)
self.matchesFunction = matches
Entry.__init__(self, *args, **kwargs)
self.focus()
self.autocompleteList = autocompleteList
self.var = self["textvariable"]
if self.var == '':
self.var = self["textvariable"] = StringVar()
self.var.trace('w', self.changed)
self.bind("<Right>", self.selection)
self.bind("<Up>", self.moveUp)
self.bind("<Down>", self.moveDown)
self.listboxUp = False
def changed(self, name, index, mode):
if self.var.get() == '':
if self.listboxUp:
self.listbox.destroy()
self.listboxUp = False
else:
words = self.comparison()
if words:
if not self.listboxUp:
self.listbox = Listbox(width=self["width"], height=self.listboxLength)
self.listbox.bind("<Button-1>", self.selection)
self.listbox.bind("<Right>", self.selection)
self.listbox.place(x=self.winfo_x(), y=self.winfo_y() + self.winfo_height())
self.listboxUp = True
self.listbox.delete(0, END)
for w in words:
self.listbox.insert(END, w)
else:
if self.listboxUp:
self.listbox.destroy()
self.listboxUp = False
def selection(self, event):
if self.listboxUp:
self.var.set(self.listbox.get(ACTIVE))
self.listbox.destroy()
self.listboxUp = False
self.icursor(END)
def moveUp(self, event):
if self.listboxUp:
if self.listbox.curselection() == ():
index = '0'
else:
index = self.listbox.curselection()[0]
if index != '0':
self.listbox.selection_clear(first=index)
index = str(int(index) - 1)
self.listbox.see(index) # Scroll!
self.listbox.selection_set(first=index)
self.listbox.activate(index)
def moveDown(self, event):
if self.listboxUp:
if self.listbox.curselection() == ():
index = '0'
else:
index = self.listbox.curselection()[0]
if index != END:
self.listbox.selection_clear(first=index)
index = str(int(index) + 1)
self.listbox.see(index) # Scroll!
self.listbox.selection_set(first=index)
self.listbox.activate(index)
def comparison(self):
return [w for w in self.autocompleteList if self.matchesFunction(self.var.get(), w)]
def matches(fieldValue, acListEntry):
pattern = re.compile(re.escape(fieldValue) + '.*', re.IGNORECASE)
return re.match(pattern, acListEntry)
# entry = AutocompleteEntry(autocompleteList, f1, listboxLength=6, width=32, matchesFunction=matches)
# entry.place(x=0, y=0)
# ------------------------------------------------------------------------------------------------------------------
data = json.load(open("Related/data.json")) #loading and storing the data from json file
# input text to speech
def in_text_to_speech(**kwargs):
if 'text' in kwargs:
text = kwargs['text']
else:
text = inputentry.get() # get text content
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
engine.stop()
# in_b.configure(command=read_text)
# output text to speech
def out_text_to_speech(**kwargs):
if 'text' in kwargs:
text = kwargs['text']
else:
text = outputtxt.get(1.0, 'end') # get text content
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
engine.stop()
# out_b.configure(command=read_text)
def input_speech():
r = sr.Recognizer()
inputentry.delete(0, END)
inputentry.insert(0, "Listening... Speak now...")
with sr.Microphone() as source:
# print("Listening... Speak now...")
audio = r.listen(source)
try:
text = r.recognize_google(audio)
inputentry.delete(0, END)
inputentry.insert(0,text)
# print("You said : {}".format(text))
except:
inputentry.delete(0, END)
inputentry.insert(0, "Didn't get that. Try again...")
# function defined th=o clear both the input text and output text --------------------------------------------------
def clear_text():
inputentry.delete(0, END)
outputtxt.delete("1.0","end")
def search_word():
word = inputentry.get()
# word = inputtxt.get("1.0", "end-1c") # first we get the word from the inputtxt and store it in word variable
# print(word)
word = word.lower() # converting word into lowercase
# CASE 1 : If input text area is empty, and clicked on search button
if word == "":
# lbl.config(text="You Entered Nothing! Please Enter Some Text.")
buffer = io.StringIO() # we are creating a buffer
print("You Entered Nothing! Please Enter Some Text.", file=buffer) # then this message is displayed
output = buffer.getvalue()
outputtxt.delete('1.0', END) # first clearing the previous output textarea
outputtxt.insert(END, output) # and then printing the new output
buffer.flush() # flushing the buffer we created
# CASE 2 : if word is present in data
elif word in data:
str = ""
cnt = 0
for i in data[word]: # we get output in list form , so we convert it into different line of string
cnt = cnt + 1
str_cnt = f'{cnt}'
str += (str_cnt + ".) ")
str += i
str += "\n\n"
# lbl.config(text = str)
# and printing the string in th output
buffer = io.StringIO()
print("Meaning of word \"" + word + "\" : \n\n" + str, file=buffer)
output = buffer.getvalue()
outputtxt.delete('1.0', END)
outputtxt.insert(END, output)
buffer.flush()
# CASE 3 : if word enetered is any noun or title
elif word.title() in data:
str = ""
cnt = 0
for i in data[word.title()]: # first we convert to output list to string
cnt = cnt + 1
str_cnt = f'{cnt}'
str += (str_cnt + ".) ")
str += i
str += "\n\n"
# lbl.config(text = str)
# print the output
buffer = io.StringIO()
print("Meaning of word \"" + word + "\" : \n\n" + str, file=buffer)
output = buffer.getvalue()
outputtxt.delete('1.0', END)
outputtxt.insert(END, output)
buffer.flush()
# CASE 4 : if uppercase of word we entered is there in data
elif word.upper() in data:
str = ""
cnt = 0
for i in data[word.upper()]:
cnt = cnt + 1
str_cnt = f'{cnt}'
str += (str_cnt + ".) ")
str += i
str += "\n\n"
# lbl.config(text = str)
buffer = io.StringIO()
print("Meaning of word \"" + word + "\" : \n\n" + str, file=buffer)
output = buffer.getvalue()
outputtxt.delete('1.0', END)
outputtxt.insert(END, output)
buffer.flush()
# CASE 5 : If word is not present in data, means we find the closest word which is in data and print its meaning
elif len(get_close_matches(word, data.keys())) > 0: # case of close matches
suggested_word = ""
for i in get_close_matches(word, data.keys())[0]:
suggested_word += i
suggested_meaning = ""
cnt = 0
for i in data[get_close_matches(word, data.keys())[0]]:
cnt = cnt + 1
str_cnt = f'{cnt}'
suggested_meaning += (str_cnt + ".) ")
suggested_meaning += i
suggested_meaning += "\n\n"
# lbl.config(text="Meaning of closest word \"" + suggested_word + "\" : " + suggested_meaning)
buffer = io.StringIO()
print("Meaning of closest word \"" + suggested_word + "\" : \n\n" + suggested_meaning, file=buffer)
output = buffer.getvalue()
outputtxt.delete('1.0', END)
outputtxt.insert(END, output)
buffer.flush()
# CASE 6 : If it even failed to find the closest word also, then print that you have entered wrong word
else:
# lbl.config(text = "You have entered wrong word!")
buffer = io.StringIO()
print("You have entered some wrong word!", file=buffer)
output = buffer.getvalue()
outputtxt.delete('1.0', END)
outputtxt.insert(END, output)
buffer.flush()
window = tk.Tk()
window.title ("English Dictionary")
window.geometry('1000x500')
window.state('zoomed') # for default maximize way
# for writing Dictionary label, at the top of window
dic = tk.Label(text = "ENGLISH DICTIONARY", font=("Arial", 50), fg="magenta") # same way bg
dic.place(x = 400, y = 10)
start1 = tk.Label(text = "Enter the text you want to search...", font=("Arial", 30), fg="green") # same way bg
start1.place(x = 450, y = 100)
myname = StringVar(window)
firstclick1 = True
def on_inputentry_click(event):
"""function that gets called whenever entry1 is clicked"""
global firstclick1
if firstclick1: # if this is the first time they clicked it
firstclick1 = False
inputentry.delete(0, "end") # delete all the text in the entry
# Taking input from TextArea
# inputentry = Entry(window,font=("Arial", 35), width=33, border=2)
inputentry = AutocompleteEntry(autocompleteList, window,font=("Arial", 35) , width=33, border=2, matchesFunction=matches)
inputentry.insert(0, 'Enter the word you want to search...')
inputentry.bind('<FocusIn>', on_inputentry_click)
inputentry.place(x=320, y=160)
# # creating speech to text button
speech_in_b = Button(window,text="🎙",command= input_speech,font=("Arial", 18), bg = "light yellow", fg = "green", borderwidth=3, relief="raised").place(x = 1200, y = 163)
# # Creating Search Button
Button(window,text="🔍 SEARCH",command= search_word,font=("Arial", 20), bg = "light green", fg = "blue", borderwidth=3, relief="raised").place(x = 370, y = 250)
# # creating clear button
Button(window,text="🧹 CLEAR",command= clear_text,font=("Arial", 20), bg = "orange", fg = "blue", borderwidth=3, relief="raised").place(x = 615, y = 250)
# # creating text to speech button
in_b = Button(window,text="🔊 TEXT TO SPEECH",command= in_text_to_speech,font=("Arial", 20), bg = "yellow", fg = "blue", borderwidth=3, relief="raised").place(x = 840, y = 250)
# # Output TextBox Creation
outputtxt = tk.Text(window,height = 15, width = 100, font=("Arial", 15), bg = "light yellow", fg = "brown", borderwidth=3, relief="solid")
outputtxt.place(x=200, y = 350)
def exit_win():
if mbox.askokcancel("Exit", "Do you want to exit?"):
window.destroy()
# # creating exit button
Button(window,text="❌ EXIT",command= exit_win,font=("Arial", 20), bg = "red", fg = "black", borderwidth=3, relief="raised").place(x = 1350, y = 20)
# # creating text to speech button
out_b = Button(window,text="🔊 TEXT TO SPEECH",command= out_text_to_speech,font=("Arial", 20), bg = "yellow", fg = "blue", borderwidth=3, relief="raised").place(x = 600, y = 720)
keypad = Keypad(window)
# # creating speech to text button
v_keypadb = Button(window,text="⌨",command= lambda:keypad.show(inputentry),font=("Arial", 18), bg = "light yellow", fg = "green", borderwidth=3, relief="raised").place(x = 1260, y = 163)
window.protocol("WM_DELETE_WINDOW", exit_win)
window.mainloop()
# # data we got from data.json file
#
# # -----------------------------------------------------------------------------------------------------
# import io # used for printing the output in textarea
# import json # imported json, because our data is in json form
# from difflib import get_close_matches # imported get close matches from difflib
# import tkinter as tk # imported tkinter
# from tkinter import *
# # from PIL import Image, ImageTk # for background image
# # ----------------------------------------------------------------------------------------------------
#
#
# # first loads the data of json file in variable data.json
# data = json.load(open("data.json"))
#
# # def clear_text():
# # word = inputtxt.get("1.0", "end-1c")
# # print(type(word))
#
# # ----------------------------------------------------------------------------------------------------
# # defined function for translating
# def translate():
# word = inputtxt.get("1.0", "end-1c")
# # print(word)
# word = word.lower()
# if word == "":
# # lbl.config(text="You Entered Nothing! Please Enter Some Text.")
#
# buffer = io.StringIO()
# print("You Entered Nothing! Please Enter Some Text.", file=buffer)
# output = buffer.getvalue()
# outputtxt.delete('1.0', END)
# outputtxt.insert(END, output)
# buffer.flush()
#
# elif word in data: # is word is not present it will print None
# str = ""
# cnt = 0
# for i in data[word]:
# cnt = cnt + 1
# str_cnt = f'{cnt}'
# str+=(str_cnt + ".) ")
# str+=i
# str+="\n\n"
# # lbl.config(text = str)
#
# buffer = io.StringIO()
# print("Meaning of word \"" + word + "\" : \n\n" + str, file=buffer)
# output = buffer.getvalue()
# outputtxt.delete('1.0', END)
# outputtxt.insert(END, output)
# buffer.flush()
#
# elif word.title() in data: # when word entered is title
# str = ""
# cnt = 0
# for i in data[word.title()]:
# cnt = cnt + 1
# str_cnt = f'{cnt}'
# str += (str_cnt + ".) ")
# str += i
# str += "\n\n"
# # lbl.config(text = str)
#
# buffer = io.StringIO()
# print("Meaning of word \"" + word + "\" : \n\n" + str, file=buffer)
# output = buffer.getvalue()
# outputtxt.delete('1.0', END)
# outputtxt.insert(END, output)
# buffer.flush()
#
# elif word.upper() in data:
# str = ""
# cnt = 0
# for i in data[word.upper()]:
# cnt = cnt + 1
# str_cnt = f'{cnt}'
# str += (str_cnt + ".) ")
# str += i
# str += "\n\n"
# # lbl.config(text = str)
#
# buffer = io.StringIO()
# print("Meaning of word \"" + word + "\" : \n\n" + str, file=buffer)
# output = buffer.getvalue()
# outputtxt.delete('1.0', END)
# outputtxt.insert(END, output)
# buffer.flush()
#
# elif len(get_close_matches(word, data.keys())) > 0: # case of close matches
# suggested_word = ""
# for i in get_close_matches(word, data.keys())[0]:
# suggested_word += i
# suggested_meaning = ""
# cnt = 0
# for i in data[get_close_matches(word, data.keys())[0]]:
# cnt = cnt + 1
# str_cnt = f'{cnt}'
# suggested_meaning += (str_cnt + ".) ")
# suggested_meaning += i
# suggested_meaning += "\n\n"
#
# # lbl.config(text="Meaning of closest word \"" + suggested_word + "\" : " + suggested_meaning)
#
# buffer = io.StringIO()
# print("Meaning of closest word \"" + suggested_word + "\" : \n\n" + suggested_meaning, file=buffer)
# output = buffer.getvalue()
# outputtxt.delete('1.0', END)
# outputtxt.insert(END, output)
# buffer.flush()
#
#
# # print("Did you mean %s instead " % get_close_matches(word, data.keys())[0])
# # decide = input("Press y for yes and n for no : ")
# # if decide == "y": # if pressed y, it will give meaning of suggested word
# # print(data[get_close_matches(word, data.keys())[0]])
# # elif decide == "n":
# # lbl.config(text="Meaning : " + data[word])
# # print("None")
# # else:
# # lbl.config(text="Meaning : " + data[word])
# # print("You have entered wrong word!")
# else:
# # lbl.config(text = "You have entered wrong word!")
#
# buffer = io.StringIO()
# print("You have entered some wrong word!", file=buffer)
# output = buffer.getvalue()
# outputtxt.delete('1.0', END)
# outputtxt.insert(END, output)
#
# buffer.flush()
#
# # ----------------------------------------------------------------------------------------------------
#
#
# # ----------------------------------------------------------------------------------------------------
# # Top level window
# frame = tk.Tk()
# frame.title("Dictionary")
# frame.geometry('1000x500')
# frame.state('zoomed') # for default maximize way
# # frame.configure(background='grey') # for background color of gui window
#
# # bg image part ---------------- working but not for background ------------------------------------------
#
# # path = "images/bgimage.jpg"
# # # Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object.
# # img = ImageTk.PhotoImage(Image.open(path))
# # # The Label widget is a standard Tkinter widget used to display a text or image on the screen.
# # panel = tk.Label(frame, image = img)
# # # The Pack geometry manager packs widgets in rows or columns.
# # panel.pack(side = "bottom", fill = "both", expand = "no")
#
# # ----------------------------------------------------------------------
#
# dic = tk.Label(text = "DICTIONARY", font=("Arial", 50), fg="magenta",underline=0) # same way bg
# dic.pack()
#
# start = tk.Label(text = "Enter the word you want to search : ", font=("Arial", 30), fg="red")
# start.pack(padx=6, pady=20)
#
# # Input TextBox Creation
# inputtxt = tk.Text(frame,height = 5, width = 60, font=("Arial", 15), bg = "light yellow",fg = "brown", borderwidth=3, relief="solid")
# inputtxt.pack()
#
# # Button Creation
# printButton = tk.Button(frame,text="SEARCH",command= lambda: translate(),font=("Arial", 20), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
# printButton.pack(padx=6, pady=20)
#
# # printButton = tk.Button(frame,text="Clear",command= lambda: clear_text(),font=("Arial", 20), bg = "light green", fg = "blue")
# # printButton.pack()
#
# # Label Creation
# # lbl = tk.Label(frame, text = "Find Meaning Here!",font=("Arial", 20), fg = "brown")
# # lbl.pack(padx=6, pady=20)
#
# # lbl1 = tk.Label(frame, text = "Next Line!",font=("Arial", 20), fg = "brown")
# # lbl1.pack(padx=6, pady=20)
#
# # Output TextBox Creation
# outputtxt = tk.Text(frame,height = 15, width = 100, font=("Arial", 15), bg = "light yellow", fg = "brown", borderwidth=3, relief="solid")
# outputtxt.pack()
#
# frame.mainloop()
#
# # ----------------------------------------------------------------------------------------------------
'''
# code only when working with console
# data we got from data.json file
import json # imported json, because our data is in json form
from difflib import get_close_matches # imported close matches from difflib
# first loads the data of json file in variable data.json
data = json.load(open("data.json"))
# # printing the read data on console
# print(data)
#
# # printing for particular word
# print(data["smog"])
# print(data["access road"])
# # print(data["SMOG"])
# defined function for translating
def translate(word):
word = word.lower()
if word in data: # is word is not present it will print None
return data[word]
elif word.title() in data: # when word entered is title
return data[word.title()]
elif word.upper() in data:
return data[word.upper()]
elif len(get_close_matches(word,data.keys())) > 0: # case of close matches
print("Did you mean %s instead " %get_close_matches(word,data.keys())[0])
decide = input("Press y for yes and n for no : ")
if decide == "y": # if pressed y, it will give meaning of suggested word
return data[get_close_matches(word,data.keys())[0]]
elif decide == "n":
return None
else:
return "You have entered wrong word!"
else:
return "You have entered wrong word!"
word = input("Enter the word you want to search : ")
# word_meaning = data[word]
word_meaning = translate(word)
# print(word_meaning) # incase of interface it will print the output in list format
cnt = 0
if type(word_meaning) == list:
for item in word_meaning:
cnt = cnt + 1
print(cnt,"->", item)
else:
print(word_meaning)
'''