Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Gui:
- def __init__(self, master=None):
- if master is None:
- return
- else:
- self.word = StringVar()
- self.word_meaning = None
- self.app_frame = Frame(master)
- self.app_frame.grid()
- self.create_app_frame()
- self.entry_widget = Entry(self.app_frame, textvariable=self.word)
- self.button_widget = Button(self.app_frame, text='Meaning', command=self.__handler_entry)
- self.text_widget = Text(self.app_frame, height=10, width=30)
- self.crete_app_frame()
- def crete_app_frame(self):
- self.entry_widget.grid(row=0, column=0)
- self.button_widget.grid(row=0, column=1)
- self.text_widget.grid(row=1, column=0, columnspan=2)
- def get_word(self):
- return self.word.get()
- def set_word_meaning(self, meaning):
- self.word_meaning = meaning
- def __handler_entry(self):
- self.text_widget.delete(0., END)
- self.text_widget.insert(END, self.word_meaning)
- class InteractiveDictionary:
- def __init__(self, filename):
- with open(filename, 'r') as file:
- self.data = json.load(file)
- def get_meaning(self, term):
- print('-------------------')
- print(f"world is:{term}")
- print('-------------------')
- term = str(term)
- term = term.lower()
- if term in self.data:
- return self.data[term]
- else:
- return "The world you're looking for doesn't exist."
- if __name__ == '__main__':
- window = Tk()
- window.title('Interactive Dictionary')
- dictionary = InteractiveDictionary('words.json')
- app = Gui(master=window)
- word = app.get_word()
- word_meaning = dictionary.get_meaning(word)
- if type(word_meaning) == list:
- for i in word_meaning:
- app.set_word_meaning(i)
- else:
- app.set_word_meaning(word_meaning)
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement