python 2.7 - Colorful dropdown menu in tkinter -


is possible add colorful items in dropdown in tkinter? dropdown take values enum class. example, enum class has 'red,yellow,green' elements. sections of dropdown green, red, yellow colors according element. how can make that?

adding colors menu possible keywords foreground , background; take look.

try:     import tkinter tk except:     import tkinter tk  root = tk.tk()  menubar = tk.menu(root)  filemenu = tk.menu(menubar,tearoff=0)  filemenu.add_command(label="text 1") filemenu.add_command(label='text 2', foreground = 'blue') filemenu.add_command(label='text 3',background='green')  # entire dropdown menu has been given color editmenu = tk.menu(menubar,tearoff=0,foreground = 'green') editmenu.add_command(label='copy') editmenu.add_command(label='paste')  menubar.add_cascade(menu=filemenu, label="file") menubar.add_cascade(menu=editmenu, label="edit")  root.config(menu=menubar)  root.mainloop() 

taking colors predefined list, involves for-loop.

try:     import tkinter tk except:     import tkinter tk  root = tk.tk()  menubar = tk.menu(root,foreground='red') filemenu = tk.menu(menubar,tearoff=0)  text = ['text 1', 'text 2', 'text 3'] color = ['green','red','yellow']  a,b in zip(text,color):     filemenu.add_command(label=a,foreground=b)  menubar.add_cascade(menu=filemenu, label="file") root.config(menu=menubar) root.mainloop() 

edit: converted code 2.7.


Comments