Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tkinter Optionmenu Too Narrow on Mac #87143

Closed
zjdavid mannequin opened this issue Jan 20, 2021 · 5 comments
Closed

Tkinter Optionmenu Too Narrow on Mac #87143

zjdavid mannequin opened this issue Jan 20, 2021 · 5 comments
Labels
3.9 only security fixes topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@zjdavid
Copy link
Mannequin

zjdavid mannequin commented Jan 20, 2021

BPO 42977
Nosy @terryjreedy, @serhiy-storchaka, @E-Paine, @zjdavid
Files
  • TKinter Menu issue.png: Screenshot of the issue
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-01-24.12:18:36.585>
    created_at = <Date 2021-01-20.14:48:54.306>
    labels = ['type-bug', 'expert-tkinter', '3.9']
    title = 'Tkinter Optionmenu Too Narrow on Mac'
    updated_at = <Date 2021-01-25.03:57:26.542>
    user = 'https://github.com/zjdavid'

    bugs.python.org fields:

    activity = <Date 2021-01-25.03:57:26.542>
    actor = 'zjdavid'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-01-24.12:18:36.585>
    closer = 'serhiy.storchaka'
    components = ['Tkinter']
    creation = <Date 2021-01-20.14:48:54.306>
    creator = 'zjdavid'
    dependencies = []
    files = ['49752']
    hgrepos = []
    issue_num = 42977
    keywords = []
    message_count = 5.0
    messages = ['385345', '385426', '385555', '385578', '385600']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'serhiy.storchaka', 'epaine', 'zjdavid']
    pr_nums = []
    priority = 'normal'
    resolution = 'third party'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue42977'
    versions = ['Python 3.9']

    @zjdavid
    Copy link
    Mannequin Author

    zjdavid mannequin commented Jan 20, 2021

    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.

    @zjdavid zjdavid mannequin added 3.9 only security fixes topic-tkinter type-bug An unexpected behavior, bug, or error labels Jan 20, 2021
    @E-Paine
    Copy link
    Mannequin

    E-Paine mannequin commented Jan 21, 2021

    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.

    @terryjreedy
    Copy link
    Member

    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.

    @serhiy-storchaka
    Copy link
    Member

    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.

    @zjdavid
    Copy link
    Mannequin Author

    zjdavid mannequin commented Jan 25, 2021

    Thanks for your help! I agree that it is probably a Tk issue. I will contact them and back with more information.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes topic-tkinter type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants