|
1 | 1 | from tkinter import *
|
| 2 | +from tkinter import messagebox |
| 3 | +from PyDictionary import PyDictionary |
2 | 4 |
|
| 5 | +# Creating Tkinter Scaffold |
3 | 6 | root = Tk()
|
4 | 7 | root.title("Dictionary")
|
5 | 8 | root.geometry("500x400")
|
6 | 9 |
|
| 10 | +# Initialize dictionary objecy |
| 11 | +dictionary = PyDictionary() |
7 | 12 |
|
8 | 13 | def getMeaning():
|
9 |
| - frame1 = Frame(root) |
10 |
| - Label(frame1, text="Meaning:- ", font=("Helvetica 10 bold")).pack(side=LEFT) |
11 |
| - meaning = Label(frame1, text="", font=("Helvetica 10")) |
12 |
| - meaning.pack() |
13 |
| - frame1.pack(pady=10) |
14 |
| - |
| 14 | + response=dictionary.meaning(word.get()) |
| 15 | + if(response): |
| 16 | + if('Noun' in response): |
| 17 | + meaning=response['Noun'][0] |
| 18 | + elif('Verb' in response): |
| 19 | + meaning=response['Verb'][0] |
| 20 | + elif('Adjective' in response): |
| 21 | + meaning=response['Adjective'][0] |
| 22 | + else: |
| 23 | + meaning="Invalid word" |
| 24 | + else: |
| 25 | + messagebox.showinfo("Error","Please add a Noun, Pronoun, verb or a valid word.") |
| 26 | + # Show meaning in frame |
| 27 | + meaning_label.config(text=meaning) |
| 28 | + |
15 | 29 |
|
16 | 30 | # Heading Label
|
17 |
| -heading_label = Label(root, text = "DICTIONARY", font=("Helvetica 21 bold")) |
| 31 | +heading_label = Label(root, text = "DICTIONARY", font=("Helvetica 35 bold"),foreground='Blue') |
18 | 32 | heading_label.config(anchor=CENTER)
|
19 | 33 | heading_label.pack(pady=10)
|
20 | 34 |
|
| 35 | +# Frame for search box and search button |
21 | 36 | frame = Frame(root)
|
22 | 37 | Label(frame, text="Enter Word", font=("Helvetica 15 bold")).pack(side=LEFT)
|
23 | 38 | word = Entry(frame, font=("Helvetica 15 bold"))
|
24 | 39 | word.pack(padx=10)
|
25 | 40 | frame.pack()
|
26 | 41 |
|
27 |
| -search_button=Button(root, text="Search Word", font=("Helvetica 15 bold"), command=getMeaning) |
| 42 | +search_button=Button(root, text="Search Word",font=("Helvetica 15 bold"),relief=RIDGE,borderwidth=3,cursor="hand2",foreground='Green', command=getMeaning) |
28 | 43 | search_button.config(anchor=CENTER)
|
29 | 44 | search_button.pack(pady=10)
|
30 | 45 |
|
| 46 | +# Frame to display meaning |
| 47 | +frame1 = Frame(root) |
| 48 | +Label(frame1, text="Meaning : ", font=("Helvetica 15 bold")).pack(side=LEFT) |
| 49 | +meaning_label = Label(frame1, text="", font=("Helvetica 12")) |
| 50 | +meaning_label.pack(pady=5) |
| 51 | +frame1.pack(pady=10) |
31 | 52 |
|
32 | 53 | # Execute Tkinter
|
33 | 54 | root.mainloop()
|
0 commit comments