1+ from tkinter import *
2+ import tkinter as tk
3+ from tkinter import ttk
4+ from tkinter import messagebox
5+ from PIL import ImageTk , Image
6+ from PyDictionary import PyDictionary
7+ from googletrans import Translator
8+
9+ root = tk .Tk ()
10+ root .title ('Dictionary' )
11+ root .geometry ('600x300' )
12+ root ['bg' ] = 'white'
13+ frame = Frame (root ,width = 200 ,height = 300 ,borderwidth = 1 ,relief = RIDGE )
14+ frame .grid (sticky = "W" )
15+
16+
17+ def get_meaning ():
18+ dictionary = PyDictionary ()
19+ get_word = entry .get ()
20+ langauages = langauage .get ()
21+
22+ if get_word == "" :
23+ messagebox .showerror ('Dictionary' ,'please write the word' )
24+
25+ elif langauages == 'English-to-English' :
26+ d = dictionary .meaning (get_word )
27+ output .insert ('end' ,d ['Noun' ])
28+
29+ elif langauages == 'English-to-Hindi' :
30+ translator = Translator ()
31+ t = translator .translate (get_word , dest = 'hi' )
32+ output .insert ('end' ,t .text )
33+
34+ def quit ():
35+ root .destroy ()
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+ img = ImageTk .PhotoImage (Image .open ('dict.png' ))
49+ pic = Label (root , image = img )
50+ pic .place (x = 40 ,y = 70 )
51+
52+ word = Label (root ,text = "Enter Word" ,bg = "white" ,font = ('verdana' ,10 ,'bold' ))
53+ word .place (x = 250 ,y = 23 )
54+
55+
56+
57+
58+ a = tk .StringVar ()
59+ langauage = ttk .Combobox (root , width = 20 , textvariable = a , state = 'readonly' ,font = ('verdana' ,10 ,'bold' ),)
60+
61+
62+
63+ langauage ['values' ] = (
64+ 'English-to-English' ,
65+ 'English-to-Hindi' ,
66+
67+
68+ )
69+
70+ langauage .place (x = 380 ,y = 10 )
71+ langauage .current (0 )
72+
73+
74+
75+
76+
77+
78+ entry = Entry (root ,width = 50 ,borderwidth = 2 ,relief = RIDGE )
79+ entry .place (x = 250 ,y = 50 )
80+
81+
82+ search = Button (root ,text = "Search" ,font = ('verdana' ,10 ,'bold' ),cursor = "hand2" ,relief = RIDGE ,command = get_meaning )
83+ search .place (x = 430 ,y = 80 )
84+
85+ quit = Button (root ,text = "Quit" ,font = ('verdana' ,10 ,'bold' ),cursor = "hand2" ,relief = RIDGE ,command = quit )
86+ quit .place (x = 510 ,y = 80 )
87+
88+
89+ meaning = Label (root ,text = "Meaning" ,bg = "white" ,font = ('verdana' ,15 ,'bold' ))
90+ meaning .place (x = 230 ,y = 120 )
91+
92+ output = Text (root ,height = 8 ,width = 40 ,borderwidth = 2 ,relief = RIDGE )
93+ output .place (x = 230 ,y = 160 )
94+
95+
96+
97+
98+
99+
100+ root .mainloop ()
0 commit comments