|
| 1 | +from tkinter import * |
| 2 | +from tkinter import messagebox |
| 3 | +from PyDictionary import PyDictionary |
| 4 | + |
| 5 | +# Creating Tkinter Scaffold |
| 6 | +root = Tk() |
| 7 | +root.title("Dictionary") |
| 8 | +root.geometry("500x400") |
| 9 | + |
| 10 | +# Initialize dictionary objecy |
| 11 | +dictionary = PyDictionary() |
| 12 | + |
| 13 | +def getMeaning(): |
| 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 | + |
| 29 | + |
| 30 | +# Heading Label |
| 31 | +heading_label = Label(root, text = "DICTIONARY", font=("Helvetica 35 bold"),foreground='Blue') |
| 32 | +heading_label.config(anchor=CENTER) |
| 33 | +heading_label.pack(pady=10) |
| 34 | + |
| 35 | +# Frame for search box and search button |
| 36 | +frame = Frame(root) |
| 37 | +Label(frame, text="Enter Word", font=("Helvetica 15 bold")).pack(side=LEFT) |
| 38 | +word = Entry(frame, font=("Helvetica 15 bold")) |
| 39 | +word.pack(padx=10) |
| 40 | +frame.pack() |
| 41 | + |
| 42 | +search_button=Button(root, text="Search Word",font=("Helvetica 15 bold"),relief=RIDGE,borderwidth=3,cursor="hand2",foreground='Green', command=getMeaning) |
| 43 | +search_button.config(anchor=CENTER) |
| 44 | +search_button.pack(pady=10) |
| 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) |
| 52 | + |
| 53 | +# Execute Tkinter |
| 54 | +root.mainloop() |
0 commit comments