How to make a OptionMenu maintain the same width?

31,377

Solution 1

When you use the grid command to place the widget in its parent, have the widget fill its cell (try sticky="ew")

Solution 2

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)
...

Solution 3

optionmenu.configure(width=<YOUR_WIDTH_HERE>)
Share:
31,377

Related videos on Youtube

rectangletangle
Author by

rectangletangle

Updated on September 02, 2020

Comments

  • rectangletangle
    rectangletangle over 3 years

    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?

  • technazi
    technazi over 5 years
    This does not work for me. I am using a dropdown in a frame. Yet it expands it for long options in the dropdown.
  • Sharpfawkes
    Sharpfawkes over 4 years
    An alternate could be to find the maximum width of all widgets in that column and then set the default of the variable within the option menu to be " "*(max_width/font_size_of_option_widget). The size of the widget can be obtained using widget.update() and then widget.winfo_width()

Related