Tkinter's OptionMenu
sets its width based on the currently active menu item. I'm looking for a way to make it set its width based on the widest menu item, rather than the currently selected one to prevent the widget from resizing itself when the user selects a different menu item.
The suggested answer in the question Tkinter Option Menu Widget Changing Widths hides the problem, but doesn't solve it. (Hint: Not a duplicate!) The accepted answer is to set the widget to be sticky to both W
and E
. This hides the problem as long as the suggested size for the column is wider than all of the items in the box, but doesn't actually solve the problem.
I have (and prefer to have) a grid
layout column with various widgets, which is dynamically sized based on the widths of the widgets. However, I'd prefer that the width reported by the OptionMenu
widget is that of it widest item, not the currently selected ones, as the width of the whole column changes, if the user chooses an item which is wider than any of the other items.
All suggested methods I have found so far have either been to sticky the widget W
and E
which doesn't (in itself) solve the problem in my case, and setting an arbitrary constant width unrelated to the item lengths, which I don't want to do.