Casper Josiah
Casper Josiah

Reputation: 31

How to stop tkinter OptionMenu that contains checkbutton from closing when an item is checked

I have an OptionMenu widget what I added some checkbuttons. It keeps closing when an item is check and I want it to stop doing this here's the code

drop1=OptionMenu(frame2, variable=clicked1,value="Options :")
other_variables={}
for o in other:
drop1['menu'].addcheckbutton(label=o,onvalue=1,offvalue=2,variable=var4, command=checkedOther)

Other is a list containing the items that need to be selected

Upvotes: 0

Views: 163

Answers (1)

acw1668
acw1668

Reputation: 46669

You can't stop the menu from closing, but you can show it back inside checkedOther() function:

def checkedOther(*args):
    # show the popup menu
    x, y, h = drop1.winfo_rootx(), drop1.winfo_rooty(), drop1.winfo_height()
    drop1['menu'].post(x, y+h)

Upvotes: 1

Related Questions