add a separator to an option menu in python with Tkinter
I've found a better way than my previous answer.
The OptionMenu's dropdown list is just a Tkinter Menu()
class and it has all the functionalities of Menu()
. So you can add separators in OptionMenu by access the Menu object inside the OptionMenu class.
Example:
Op = OptionMenu(root, var, 'First', 'Second', 'Third')Op.pack()Op['menu'].insert_separator(1)
Update Code:
from tkinter import *root = Tk()root.geometry("1430x840")var1 = StringVar()opt1 = OptionMenu(root, var1, 'Mockups', 'Assets', 'Symbols', # here is where the separator should be 'Trash')opt1['menu'].insert_separator(3)opt1.pack(side=LEFT, anchor=W)var1.set('')root.mainloop()