How to make a OptionMenu maintain the same width?

rectangletangle picture rectangletangle · Apr 12, 2011 · Viewed 27.7k times · Source

I have a snippet which creates an OptionMenu widget.

...
options = ('White', 'Grey', 'Black', 'Red', 'Orange', 
           'Yellow', 'Green', 'Blue', 'Cyan', 'Purple')
var = StringVar()
optionmenu = OptionMenu(par, var, *options)
optionmenu.grid(column=column, row=row)
...

One problem I've encountered is every time a new option is selected, the width of the widget changes. I believe this is due to the text within the widget changing widths. How do I make the widget hold a consistent width?

Answer

Symon picture Symon · Apr 12, 2011

To the best of my knowledge, you can use optionmenu.config(width=<YOUR_WIDTH>) as follows:

...
optionmenu = OptionMenu(par, var, *options)
optionmenu.config(width=<YOUR_WIDTH>)
optionmenu.grid(column=column, row=row)
...