Changing default icon in tkinter OptionMenu?

user1214192 picture user1214192 · Nov 4, 2012 · Viewed 8.5k times · Source

I am trying to remove the default "box like" icon from the tkinter OptionMenu and replace it with my own image file. below is the code I have to date. It is working but I had to add the last line to get it to display the arrow image and for the OptionMenu to function. However, the arrow image is always imedately after the text rather than at the far right of the OptionMenu and sticky does not seam to be aplying hence the width=140. I am working in Python 2.6.

Any sugegestions for moving the image to the right?

Default What I am Getting

...
arrow = PhotoImage(file='arrow.gif')
om = OptionMenu(root,myVar,*myOptList)
om.grid(sticky=W+E,padx=5,pady=5)
om.config(indictoron=0,compound='right',image=arrow,width=140)
om.image=arrow
...

Answer

Peter Wood picture Peter Wood · Mar 22, 2016

You can use the ttk.Combobox widget instead:

om = Combobox(root, values=*myOptList)
om.set(myVar)
om.grid(sticky=W + E, padx=5, pady=5)
om.config(compound='right', width=140)