Tkinter optionMenu Resize

Terry Reedy tjreedy at udel.edu
Sun May 19 15:34:41 EDT 2019


On 5/18/2019 10:40 AM, Cummins, Hayden wrote:
> Hi! I've been having a lot of trouble resizing the Tkinter optionMenu feature due to my inexperience in Python. Is there a way to resize the option menu? If so, how? I've tried using the config function and it makes it so the program no longer executes. I also can't find any articles about this problem at all across the internet, so any help would be greatly appreciated. Source code to follow.

This is a no-attachment list.  Put *minimal* code inline.

An OptionMenu is a Menubutton subclass initialized with a default 
configuration and with a drop-down menu for which all items have the 
same callback.  The following works for me to give the button a constant 
width regardless of the selection.

from tkinter import *
r = Tk()
s = StringVar()
om = OptionMenu(r, s, 'a', 'boat', 'cantilever')
om.pack()
om['width'] = 10  # len('cantilever')
r.mainloop()  # Omit this while developing in IDLE.

If using IDLE with mainloop() disabled, you can experiment with 
configuration settings at the interactive prompt.

Helpful (but not perfect) tkinter reference:
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/menubutton.html
shows the configuration settings for menubutton.
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/optionmenu.html
shows how to set an initial value so that the button is not initially blank.

-- 
Terry Jan Reedy




More information about the Python-list mailing list