Python Tkinter: OptionMenu modify dropdown list width
There is no way to change the width of the dropdown.
You might want to consider the ttk.Combobox widget. It has a different look that might be what you're looking for.
doing drop down name.config(width = width)works very well with resizing the drop down box.i managed to get it to work with.
drop1.config(width = 20)
Just letting you know width 20 is quite long.
One idea is to pad the right side (or left, or both) with spaces. Then, when you need the selected value, strip it with str
strip
. Not great, but better than nothing.
from tkinter import ttkimport tkinter as tkroot = tk.Tk()def func(selected_item): print(repr(selected_item.strip()))max_len = 38omvar = tk.StringVar()choices = ['Default Choice', 'whoa', 'this is a bit longer'] + ['choice'+str(i) for i in range(3)]padded_choices = [x+' '*(max_len-len(x)) for x in choices]om = ttk.OptionMenu(root, omvar, 'Default Choice', *padded_choices, command=func)om.config(width=30)om.grid(row=0, column=0, padx=20, pady=20, sticky='nsew')root.mainloop()