Avoiding Tkinter OptionMenu button resizing
Asked Answered
R

3

6

I've the following OptionMenu:

self.textoprioridad = Label(self.frameTwo, text = "Prioridad: ", justify="center")
self.textoprioridad.grid(row=n, column=4)
var2 = StringVar()
menu2 = OptionMenu(self.frameTwo, var2, "Primera pieza", "Esta semana", "Normal", "Baja")
menu2.grid(row=n, column=5, ipadx=10)
var2.set("Primera pieza")
self.optionmenus_prioridad.append((menu2, var2))

That shows something like this:

enter image description here

The thing is that if I choose Normal from the list, the button resized and it makes smaller: enter image description here

I would like to know if it's any way to keep the OptionMenu button with the initial size, like this: enter image description here

Thanks in advance.

Revivify answered 5/8, 2013 at 9:49 Comment(0)
B
7

Specify width by config(width=desired-width):

menu2.config(width=20)
Barbicel answered 5/8, 2013 at 9:57 Comment(0)
C
3

One solution is to give the widget a specific size by specifying the width attribute:

menu2.configure(width=20)

Another solution is to have the widgets "stick" to the sides of their container:

menu2.grid(row=n, column=5, ipadx=10, sticky="ew")

Using the second option, the widgets can still possibly resize, but they are constrained by the size of the column they are in. If one resizes they all resize, guaranteeing they will always be uniform in size.

Colourable answered 5/8, 2013 at 10:40 Comment(0)
Y
3

Specify a sticky in the grid method so that it knows how wide to needs to be:

button.grid(sticky="WE")

This method is better than specifying a set width in the grid method becuase it means that the widget will always span the length of the column.

sticky is a key that shows where the widget will stick too. if you say sticky='W' than the widget will stick to the left of the column. By making is EW it will stick to the left and right, and therefore stretch it's self to the length of the column. NOTE: it's North South East West

Yalonda answered 5/8, 2013 at 10:43 Comment(1)
A much better way... then what? Remember, answers may not show up in the order that you see them, so if you're referring to some other answer, you need to be more specific.Colourable

© 2022 - 2024 — McMap. All rights reserved.