Skip to content

Commit 7ee522d

Browse files
authored
Python Dictionary
1 parent 6240d4b commit 7ee522d

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

OTHERS/PythonDictionary/data.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

OTHERS/PythonDictionary/dictionary.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from tkinter import *
2+
from PyDictionary import PyDictionary
3+
4+
# Create a window
5+
dictionary = PyDictionary()
6+
root = Tk()
7+
8+
# set geometry
9+
root.title("Dictionary")
10+
root.geometry("600x400+50+50")
11+
12+
13+
def dict():
14+
meaning.config(text=dictionary.meaning(word.get())['Noun'][0])
15+
synonym.config(text=dictionary.synonym(word.get()))
16+
antonym.config(text=dictionary.antonym(word.get()))
17+
18+
19+
# Add labels, buttons and frame
20+
Label(root, text="My Dictionary", font=(
21+
"Poppins, 20 bold"), fg="Orange").pack(pady=20)
22+
23+
# Frame 1
24+
frame = Frame(root)
25+
Label(frame, text="Enter word: ", font=(
26+
"Helvetica, 15 bold")).pack(side="left")
27+
word = Entry(frame, font=("Helvetica, 15 bold"), width=30)
28+
word.pack()
29+
frame.pack(pady=10)
30+
31+
# Frame 2
32+
frame1 = Frame(root)
33+
Label(frame1, text="Meaning: ", font=("Aerial, 15 bold")).pack(side=LEFT)
34+
meaning = Label(frame1, text="", font=("Poppins, 15"))
35+
meaning.pack()
36+
frame1.pack(pady=10)
37+
38+
# Frame 3
39+
frame2 = Frame(root)
40+
Label(frame2, text="Synonym: ", font=(
41+
"Roboto, 15 bold")).pack(side=LEFT)
42+
synonym = Label(frame2, text="", font=("Roboto, 15"))
43+
synonym.pack()
44+
frame2.pack(pady=10)
45+
46+
# Frame 4
47+
frame3 = Frame(root)
48+
Label(frame3, text="Antonym: ", font=("Helvetica, 15 bold")).pack(side=LEFT)
49+
antonym = Label(frame3, text="", font=("Helvetica, 15"))
50+
antonym.pack(side=LEFT)
51+
frame3.pack(pady=10)
52+
53+
Button(root, text="Search", font=("Helvetica, 15 bold"), command=dict).pack()
54+
55+
# Execute Tkinter
56+
root.mainloop()

OTHERS/PythonDictionary/find.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import json
2+
from difflib import get_close_matches # Step 4
3+
4+
data = json.loads(open('data.json').read()) # Step 1 - Check rando word
5+
6+
7+
def definition(name): # Step 1
8+
9+
name = name.lower() # Step 3 - convert all input into lower case
10+
11+
if name in data: # Step 2 - Error handling for non english words
12+
return data[name] # Step 2
13+
14+
elif len(get_close_matches(name, data.keys())) > 0: # Step 4
15+
# Step 4
16+
check = input("Did you mean %s instead? Enter Y if yes, otherwise N to exit: " %
17+
get_close_matches(name, data.keys())[0])
18+
if check == "Y":
19+
return data[get_close_matches(name, data.keys())[0]]
20+
elif check == "N":
21+
return "The word doesn't exist. Please double check it."
22+
else:
23+
return "We didn't understand your entry."
24+
25+
else:
26+
return "Sorry, this word is not an English word. Please double check your spelling." # Step 2
27+
# return data[name] # Step 1
28+
29+
30+
word = input('Enter a name: ') # Step 1
31+
32+
# print(definition(word)) # Step 1
33+
output = definition(word) # Step 5
34+
if type(output) == list: # Step 5
35+
for item in output:
36+
print(item)
37+
else:
38+
print(output)

0 commit comments

Comments
 (0)