Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Tkinter: OptionMenu modify dropdown list width

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)
like image 789
James the Great Avatar asked Sep 23 '14 16:09

James the Great


People also ask

How to change width of OptionMenu in tkinter?

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.

How do you use Customtkinter?

To use CustomTkinter, just place the /customtkinter folder from this repository next to your program, and then you can do import customtkinter .

How can I create a dropdown menu from a list in tkinter?

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.

What does config do in tkinter?

Python tkinter config() By using config() we can access the object's attributes after its initialisation.


2 Answers

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.

like image 95
ath0rus Avatar answered Sep 29 '22 15:09

ath0rus


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.

like image 20
Bryan Oakley Avatar answered Sep 29 '22 13:09

Bryan Oakley