Search code examples
pythontkintermenuadditionttk

How to update the dropdown options in ttk.OptionsMenu (python, tkinter, ttk)


I have found plenty of documentation on how to update a OptionsMenu object using tkinter but due to various issues revolving around my version of mac OS, I have been using ttk to build my project and I've found myself stumped when it comes to updating the options menu.

My options are coming from a list which is added using the following code:

dropdown_menu = ttk.OptionMenu(root, dropdown_menu_text, dropdown_options[0], *dropdown_options)

and I am using a separate method to update the contents of the dropdown_options variable. According to the information I found, updating the optionsmenu using standard tk involves essentially clearing the options, then looping through my updated list and adding each option back again.

Is it a similar kind of logic with ttk?


Solution

  • Turns out after some more digging around I was able to find the solution myself and it was far simpler than I anticipated. Turns out the answer is simply to add the line

    dropdown_menu.set_menu(dropdown_options[0], * dropdown_options) 
    

    Assuming that dropdown_options is your updated list!