Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a OptionMenu maintain the same width?

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?

like image 637
rectangletangle Avatar asked Apr 12 '11 02:04

rectangletangle


3 Answers

optionmenu.configure(width=<YOUR_WIDTH_HERE>)
like image 140
user2155059 Avatar answered Sep 17 '22 17:09

user2155059


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)
...
like image 33
Symon Avatar answered Oct 15 '22 18:10

Symon


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

like image 16
Bryan Oakley Avatar answered Oct 15 '22 17:10

Bryan Oakley