Tkinter Dropdown options menu using Enum
As I already pointed out in a comment, you just needed to add an *
character to the line that creates the OptionMenu
widget to unpack the list of values in the list. This is required because each one of them needs to each be passed as separate argument.
Although not strictly necessary, I would also suggest changing the definition of the custom Enum
to make it a little more succinct, as well as make a few other minor changes to the code.
Here's the result:
from enum import Enumimport tkinter as tkwindow = tk.Tk()CustomEnum = Enum(value='CustomEnum', names='Option1 Option2 Option3')current = tk.StringVar(value=CustomEnum.Option1.name)tk.OptionMenu(window, current, *[option.name for option in CustomEnum]).pack()#tk.OptionMenu(window, current, *list(CustomEnum.__members__)).pack() # An alternative.window.mainloop()