classification
Title: Tkinter Optionmenu Too Narrow on Mac
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.9
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: epaine, serhiy.storchaka, terry.reedy, zjdavid
Priority: normal Keywords:

Created on 2021-01-20 14:48 by zjdavid, last changed 2021-01-25 03:57 by zjdavid. This issue is now closed.

Files
File name Uploaded Description Edit
TKinter Menu issue.png zjdavid, 2021-01-20 14:48 Screenshot of the issue
Messages (5)
msg385345 - (view) Author: DDavid (zjdavid) Date: 2021-01-20 14:48
Hello,

I am building a program with Tkinter. However, I found the Optionmenu widget has inconsistent behaviors on default lengths on a Mac and a Windows PC. 

So I set the width of an optionmenu through menu.configure(width=70). On Windows, this correctly sets the menu width to 70 when the program runs. However, on a Mac, the menu is still very narrow at the start. It only expands to 70 after I select an option. 

I have attached a screenshot to help explain the issue. It does not occur on Windows.
msg385426 - (view) Author: E. Paine (epaine) * Date: 2021-01-21 14:42
I suspect this is just a MacOS behaviour, if not then it is a Tk bug. If you really need to enforce the width, you could tell it to expand horizontally in the layout. An example of this would be as follows:

tk.Frame(root, height=1, width=300).pack()
tk.OptionMenu(root, tk.StringVar(), "test").pack(fill="x")

A bit more detail on the Tk side of things:
tkinter doesn't actually use `tk_optionMenu` and instead creates its own menubutton and menu. The issue with the menubutton width not changing also exists when working directly with Tk (`pack [menubutton .p -width 100]`). However, the same behaviour can be shown when using `tk_optionMenu`, so changing tkinter to use that instead would not fix this issue.
msg385555 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-01-23 18:00
This should likely be closed as 3rd party

 zjdavid Which python release, which macOS, which installer, which tk patchlevel?  (IDLE Help=>About displays it).

At least one of the 3.9.1 python.org mac installers installs 8.6.10.  We cannot be responsible for problems fixed in this release.
msg385578 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-24 12:18
I concur with E. Paine that you should use pack(fill="x") if you want to stretch a widget. And in any case Tkinter itself does not manage layout, it is just a wrapper around Tk, so if you think that the default layout of a button is wrong on some platforms, you should report it to the Tk team.
msg385600 - (view) Author: DDavid (zjdavid) Date: 2021-01-25 03:57
Thanks for your help! I agree that it is probably a Tk issue. I will contact them and back with more information.
History
Date User Action Args
2021-01-25 03:57:26zjdavidsetmessages: + msg385600
2021-01-24 12:18:36serhiy.storchakasetstatus: open -> closed
resolution: third party
messages: + msg385578

stage: resolved
2021-01-23 18:00:36terry.reedysetnosy: + terry.reedy
messages: + msg385555
2021-01-21 14:42:38epainesetnosy: + serhiy.storchaka, epaine
messages: + msg385426
2021-01-20 14:48:54zjdavidcreate