Tkinter optionMenu Resize
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['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:
shows the configuration settings for menubutton.
shows how to set an initial value so that the button is not initially blank.
Terry Jan Reedy