Opening a Pop-up window every time when selecting a particular option on the optionmenu using tkinter

370 Views Asked by At

On a drop-down/ option menu everytime an option is selected a pop-up should be displayed on the screen. This pop-up is another window.

#function to create pop-up
def alert_popup():
    
    root = Tk()
    root.title("title")
    
    sw = root.winfo_screenwidth()
    sh = root.winfo_screenheight()
    root.geometry('%dx%d+%d+%d' % (sw/2, sh/2, sh/2, sw/2))
    w = Label(root, text=" ", width=120, height=10)
    w.grid()
    b = Button(root, text="OK", command=root.destroy, width=10)
    b.grid()


#code to select the option and display the pop-up

drop = OptionMenu( root , clicked , *options )
drop.grid(pady= 10)
print(clicked.get())
def changed():
    print (clicked.get())
clicked.trace("w", changed)

# each time i select this particular option the pop-up should open
if(clicked.get() == "Particular Option"): 
    alert_popup()

0

There are 0 best solutions below