I have created an OptionMenu from Tkinter with a columnspan of 2. However, the dropdown list/menu does not match the width, so it does not look good. Any idea on how to match their width?
self.widgetVar = StringVar(self.top)
choices = ['', 'wire', 'register']
typeOption = OptionMenu(self.top, self.widgetVar, *choices)
typeOption.grid(column = 0, columnspan = 2, row = 0, sticky = 'NSWE', padx = 5, pady = 5)
We can maintain the width of the options by finding the maximum length from the given options. Now, by using the config(width) method, we can set the width of the OptionMenu.
To use CustomTkinter, just place the /customtkinter folder from this repository next to your program, and then you can do import customtkinter .
Let us suppose we want to create a dropdown menu of a list in an application using tkinter. In this case, we can use the Tkinter OptionMenu(win, menu_to_set, options) function. First, we will instantiate an object of StringVar(), then we will set the initial value of the dropdown menu.
Python tkinter config() By using config() we can access the object's attributes after its initialisation.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With