Home > Blockchain >  Is there a way I can stop option menus moving other option menus in Tkinter?
Is there a way I can stop option menus moving other option menus in Tkinter?

Time:11-19

The option menu in the middle should be in the centre but it is moved by the menu on the right because of its size. What can I do to fix this?
Below are some images.
This is how it should be.
When I choose a option it moves the other menus

from tkinter import *

root = Tk()

label = Label(root, text='First Second Third') 
label.grid(row=0, column=0, columnspan=3, ipadx=150, pady=30)

menu_var1 = StringVar() 
menu_var2 = StringVar() 
menu_var3 = StringVar()

menu1 = OptionMenu(root, menu_var1, 'First', 'Second', 'Third') 
menu2 = OptionMenu(root, menu_var2, 'First', 'Second', 'Third') 
menu3 = OptionMenu(root, menu_var3, 'First', 'Second', 'Third')

menu1.grid(row=1, column=0, padx=10) 
menu2.grid(row=1, column=1, padx=10) 
menu3.grid(row=1, column=2, padx=10)

root.mainloop()

CodePudding user response:

You can tell the grid manager to make the three columns to have uniform width:

root.columnconfigure((0,1,2), uniform=1)

Or give initial width (large enough to show the longest item) to the three OptionMenu:

menu1.config(width=10)
menu2.config(width=10)
menu3.config(width=10)
  • Related