Word Dictionary using Python Tkinter

PythonTkinterGUI-Programming

In this article, we will create a GUI-based dictionary using PyDictionary and Tkinter Module.

PyDictionary is a Python Module that helps to get meaning translations, antonyms and synonyms of words. It uses WordNet for getting meanings, Google for translations, and synonym.com for getting synonyms and antonyms. PyDictionary uses BeautifulSoup, Requests module as the dependencies.

In order to create the application, we will first install these modules in our environment using pip install PyDictionary

After installing, we will create a tkinter frame and some other element.

Example

# Import Required Librares
from tkinter import *
from PyDictionary import PyDictionary

# Create instances and objests
dictionary = PyDictionary()
win =Tk()

#Define the size of the window
win.geometry("700x400")

win.title("Python Dictionary")

#Define Helper Function to use the other atributes of PyDictionary Class
def dict():
   meaning.config(text=dictionary.meaning(word.get())['Noun'][0])

#Define Labels and Buttons
Label(win, text="Dictionary", font=("Times New Roman" ,20)).pack(pady=20)

# Frame 1
frame = Frame(win)
Label(frame, text="Type any Word ", font=("Poppins bold", 15)).pack(side=LEFT)
word = Entry(frame, font=("Times New Roman", 15))
word.pack()
frame.pack(pady=10)
# Frame 2
frame1 = Frame(win)
Label(frame1, text="Meaning:", font=("Aerial", 18)).pack(side=LEFT)
meaning = Label(frame1, text="", font=("Poppins",15), width= 30)
meaning.pack()
frame1.pack(pady=10)

Button(win, text="Find", font=("Poppins bold",15), command=dict).pack()

# Execute Tkinter
win.mainloop()

Output

Running the above code will create and display the Dictionary Application. However, using PyDictionary, we can add other attributes like finding synonym, antonyms, etc.

Now, type “Hello” in the textbox and click the “Find” button. It will pull the meaning of “Hello” from the dictionary.

raja
Published on 06-Mar-2021 09:13:28
Advertisements