1
- from tkinter import *
1
+ from tkinter import * #importing the necessary libraries
2
2
import json
3
3
from difflib import get_close_matches
4
4
5
- data = json .load (open ("Related/data.json" ))
5
+ data = json .load (open ("Related/data.json" )) #loading and storing the data from json file
6
6
7
7
def search (word ):
8
- if word in data :
8
+ if word in data : #if the typed word is present in the data
9
9
t1 .delete (1.0 ,END )
10
10
t1 .config (fg = 'white' )
11
11
t1 .insert (END ,data [word ])
12
- elif len (get_close_matches (word ,data .keys ()))> 0 :
12
+ elif len (get_close_matches (word ,data .keys ()))> 0 : #if the typed word is not found in data or is misspelled
13
13
t1 .config (fg = 'red' )
14
14
t1 .delete (1.0 ,END )
15
15
t1 .insert (END ,"Did you mean {} to mean : {} " .format (get_close_matches (word ,data .keys ())[0 ],data [get_close_matches (word ,data .keys ())[0 ]]))
@@ -23,17 +23,15 @@ def search(word):
23
23
label .pack ()
24
24
25
25
e1_value = StringVar ()
26
- e1 = Entry (window ,textvariable = e1_value ,bg = "black" ,fg = "white" ,justify = CENTER ,font = ('courier' , 30 , 'bold' ))
26
+ e1 = Entry (window ,textvariable = e1_value ,bg = "black" ,fg = "white" ,justify = CENTER ,font = ('courier' , 30 , 'bold' )) #for the text bar
27
27
e1 .place (relx = .185 ,rely = 0.70 ,relwidth = .63 ,relheight = .082 )
28
28
29
29
30
- b1 = Button (window ,text = "Search" ,command = lambda : search (e1_value .get ()),relief = FLAT ,bg = "black" ,fg = "white" ,font = ('courier' , 30 , 'bold' ) )
30
+ b1 = Button (window ,text = "Search" ,command = lambda : search (e1_value .get ()),relief = FLAT ,bg = "black" ,fg = "white" ,font = ('courier' , 30 , 'bold' ) ) #for the search button
31
31
b1 .place (relx = .40 ,rely = .85 ,relwidth = .2 ,relheight = .052 )
32
32
33
33
34
- t1 = Text (window ,fg = "white" ,relief = FLAT ,bg = "#444444" ,font = ('courier' , 20 , 'bold' ))
34
+ t1 = Text (window ,fg = "white" ,relief = FLAT ,bg = "#444444" ,font = ('courier' , 20 , 'bold' )) #for displaying the meaning
35
35
t1 .place (relx = .185 ,rely = .09 ,relwidth = .63 ,relheight = .50 )
36
36
37
-
38
-
39
- window .mainloop ()
37
+ window .mainloop ()
0 commit comments