How to make OptionMenu maintain the same width?

I have a fragment that 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 of the problems I encountered is every time a new option is selected, the width of the widget changes. I believe this is due to the text in the widgets changing the width. How to make widget maintain consistent width?

+7
source share
3 answers

When you use the grid command to place the widget in your parent element, add the widget to your cell (try sticky="ew" )

+10
source

As far as I know, 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) ... 
+19
source
 optionmenu.configure(width=<YOUR_WIDTH_HERE>) 
0
source

Source: https://habr.com/ru/post/885695/


All Articles