Skip to content

Commit 4bffe26

Browse files
committed
English Dictionary
1 parent b1318c6 commit 4bffe26

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Create an English Dictionary App Using Python
2+
3+
In Python, a dictionary is an unordered collection of data values, used to store data values like a map. It works in a similar manner just like the real world dictionary where all the keys are unique and of immutable data type.
4+
5+
In this guide we will be creating an interactive English dictionary which will not only allow the user to type in words to get meaning but also provide word suggestions in the case of a misspelling.
6+
7+
Read more about the Dictionary project [here](https://sweetcode.io/create-an-english-dictionary-app-using-python/)
8+
9+
## Output
10+
11+
**Terminal Output**
12+
![](https://sweetcode.io/wp-content/uploads/2022/04/program.jpg)
13+
14+
15+
**GUI Output**
16+
![](https://sweetcode.io/wp-content/uploads/2022/04/mydict.jpg)

PYTHON APPS/PythonDictionary/data.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
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()

PYTHON APPS/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)