'Merge of pop ups and drop down in python 3 for tkinter

I am trying to create a text editor in Tkinter and below is my code.

I am trying to create a feature in my GUI, when a word is selected and right click action is performed on the selected word a pop up with synonym label appears and once the label is clicked, all the synonyms for the selected word will appear as a drop down. So that user can select the most appropriate synonym. Any help with creating the same will be appreciated.

from tkinter import *
from tkinter import filedialog
from tkinter import font
from nltk.corpus import wordnet


word = None

def do_popup(event):
    try:
        right_click.tk_popup(event.x_root, event.y_root)
    finally:
        right_click.grab_release()

def synonyms(word):
    word = my_text.get(1.0,END)
    s = []
    for syn in wordnet.synsets(word):
        for lm in syn.lemmas():
            s.append(lm.name())
    return s

root = Tk()
root.title('Text Editor')
root.geometry("1200x660")


my_frame = Frame(root)
my_frame.pack(pady=5)

my_text= Text(my_frame,width=97,height=25,font=("Arial, 16"),selectbackground="grey",selectforeground="white",undo=True,yscrollcommand=text_scroll.set)
my_text.pack()


right_click = Menu(root, tearoff = 0)
right_click.add_command(label ="Synonyms",command=lambda:synonyms(word))


root.bind("<Control-Button-1>", do_popup)


root.mainloop()





Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source