0

I searched all over the internet, and couldn't find a way to update the options menu when it is pressed. I should have a method that will run after the optionsMenu is pressed, like an actual button, such that the options are immediately updated according to the above method.
Is this even possible? if there isn't such a way, is there a good alternative for this over Tkinter, which looks as good as optionsMenu?

Thanks!

5
  • 1
    What did you try? Please, spend some time reading "How to create a Minimal, Complete, and Verifiable example" and "How do I ask a good question?". You will get better results by following the tips in those articles.
    – accdias
    Commented Feb 25, 2022 at 11:26
  • 1
    It is not clear what do you mean by "update the options menu when it is pressed".
    – acw1668
    Commented Feb 25, 2022 at 11:30
  • @acw1668 suppose there is a list of users and I want to update any time I press the chooseMenu to see who is connected. So when I press the chooseMenu, I mean when I click the chooseMenu I want it to run a method that updates the options.
    – Chopin
    Commented Feb 25, 2022 at 11:38
  • 1
    "press/click the chooseMenu" Does it mean after you have selected an option in chooseMenu (an OptionMenu widget)? To be more clearly define your need, better provide a minimal reproducible example.
    – acw1668
    Commented Feb 25, 2022 at 11:42
  • @acw1668 No, it means that before you select something when you just click the menu to see what options you got.
    – Chopin
    Commented Feb 25, 2022 at 12:31

1 Answer 1

1

Instead of tkinter.OptionMenu use tkinter.ttk.Combobox, to modify the list of values of a combobox simply change it's values attribute like so -:

def add_to_combobox(new_item) :
    combobox['values'].append(new_item)

combobox = tkinter.ttk.Combobox(master, option=value, ...)
combobox['values'] = ['my', 'new', 'list']
combobox.current() # Can pass as argument the index of the list to set as default

Now, to add a new item to the combobox simply call the add_to_combobox method with the new_item to insert.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.