Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. class Gui:
  2. def __init__(self, master=None):
  3. if master is None:
  4. return
  5. else:
  6. self.word = StringVar()
  7. self.word_meaning = None
  8. self.app_frame = Frame(master)
  9. self.app_frame.grid()
  10. self.create_app_frame()
  11. self.entry_widget = Entry(self.app_frame, textvariable=self.word)
  12. self.button_widget = Button(self.app_frame, text='Meaning', command=self.__handler_entry)
  13. self.text_widget = Text(self.app_frame, height=10, width=30)
  14. self.crete_app_frame()
  15.  
  16. def crete_app_frame(self):
  17. self.entry_widget.grid(row=0, column=0)
  18. self.button_widget.grid(row=0, column=1)
  19. self.text_widget.grid(row=1, column=0, columnspan=2)
  20.  
  21. def get_word(self):
  22. return self.word.get()
  23.  
  24. def set_word_meaning(self, meaning):
  25. self.word_meaning = meaning
  26.  
  27. def __handler_entry(self):
  28. self.text_widget.delete(0., END)
  29. self.text_widget.insert(END, self.word_meaning)
  30.  
  31. class InteractiveDictionary:
  32. def __init__(self, filename):
  33. with open(filename, 'r') as file:
  34. self.data = json.load(file)
  35.  
  36. def get_meaning(self, term):
  37. print('-------------------')
  38. print(f"world is:{term}")
  39. print('-------------------')
  40. term = str(term)
  41. term = term.lower()
  42. if term in self.data:
  43. return self.data[term]
  44. else:
  45. return "The world you're looking for doesn't exist."
  46.  
  47. if __name__ == '__main__':
  48. window = Tk()
  49. window.title('Interactive Dictionary')
  50. dictionary = InteractiveDictionary('words.json')
  51. app = Gui(master=window)
  52. word = app.get_word()
  53. word_meaning = dictionary.get_meaning(word)
  54. if type(word_meaning) == list:
  55. for i in word_meaning:
  56. app.set_word_meaning(i)
  57. else:
  58. app.set_word_meaning(word_meaning)
  59. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement