FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make Tkinter.py's nametowidget work with cloned menu widgets · Issue #38464 · python/cpython · GitHub

Repository navigation

Make Tkinter.py's nametowidget work with cloned menu widgets #38464

Closed

Description

mannequin
BPO 734176
Nosy @terryjreedy, @abalkin, @serhiy-storchaka
Files
  • Tkinter.py.diffs: nametowidget patch for cloned widgets
  • nametowidget_clonedmenus.diff
  • issue734176_py3.patch: Python 3 patch
  • nametowidget_clonedmenus_2.diff
  • nametowidget_clonedmenus_3.patch
  • 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 = None
    created_at = <Date 2003-05-07.20:11:52.000>
    labels = ['type-bug', 'expert-tkinter']
    title = "Make Tkinter.py's nametowidget work with cloned menu widgets"
    updated_at = <Date 2021-07-09.21:02:53.288>
    user = 'https://bugs.python.org/gregcouch'

    bugs.python.org fields:

    activity = <Date 2021-07-09.21:02:53.288>
    actor = 'terry.reedy'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Tkinter']
    creation = <Date 2003-05-07.20:11:52.000>
    creator = 'gregcouch'
    dependencies = []
    files = ['5260', '12509', '30320', '31426', '43851']
    hgrepos = []
    issue_num = 734176
    keywords = ['patch']
    message_count = 13.0
    messages = ['43671', '43672', '78634', '114239', '114244', '189566', '189637', '189674', '195928', '270902', '271130', '271131', '397223']
    nosy_count = 6.0
    nosy_names = ['jepler', 'terry.reedy', 'belopolsky', 'gregcouch', 'gpolo', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue734176'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6']

    Linked PRs

    Activity

    1. gregcouch commented on May 7, 2003

      gregcouchmannequin
      MannequinAuthor

      Tk will clone menu widgets when they are torn off and
      it gives them names at are similar to the original
      widget's names. The patch extends the nametowidget so
      it will return the original widget when given the name
      of a cloned widget. We used this patch to provide
      balloon help in cloned menus. This patch isn't
      perfect, it will fail on clones of clones, but it is a
      big help.

      This patch was made against the latest CVS version
      1.173 of Tkinter.py but works against older
      Tkinter.py's too.

       - Greg Couch
      
    2. jepler commented on May 11, 2003

      jeplermannequin
      Mannequin

      Logged In: YES
      user_id=2772

      I don't believe that the naming convention of cloned menus is actually documented anywhere (it's certainly not documented in menu(n) of tk-8.3.5 as packaged by RedHat. The only promise that the documentation makes is that the clone "is a child of the original". (but that can be violated if "menu clone" is invoked directly:

      % menu .m
      .m
      % .m clone .n
      %
      )

      That said, the convention for automatically generated clones hasn't varied in the versions of Tk I'm aware of (at least 8.2 through 8.4) so it might be reasonable to depend on this.

      Does anybody in Python development also keep up with Tcl/Tk development? It might be reasonable to ask them to document the format of automatically generated clone names.

    3. gpolo commented on Dec 31, 2008

      gpolomannequin
      Mannequin

      Eh.. old.
      Anyway, I have made a patch against trunk now and it should work with
      any nested level of cloned menus according to how tk names cloned menus.

    4. BreamoreBoy commented on Aug 18, 2010

      BreamoreBoymannequin
      Mannequin

      A small simple patch that I see no problems with.

    5. abalkin commented on Aug 18, 2010

      Member

      Can someone post a script demonstrating the proposed feature? Is "clones of clones" issue mentioned by OP resolved in the latest patch?

      Given that nobody commented on this issue for 7 years, I am skeptical about the utility of this feature.

    6. BreamoreBoy commented on May 19, 2013

      BreamoreBoymannequin
      Mannequin

      Ten years on does anybody actually care about this? If you do the patch will need reworking as in Python 3 the code exists in lib/tkinter/init.py.

    7. gregcouch commented on May 20, 2013

      gregcouchmannequin
      MannequinAuthor

      We still apply that patch to the Python that we embed in our application
      and have for the last 10 years :-)

    8. BreamoreBoy commented on May 20, 2013

      BreamoreBoymannequin
      Mannequin

      I've attached a patch for Python 3 which I hope is okay as it's my first attempt using TortoiseHg on Windows.

    9. serhiy-storchaka commented on Aug 22, 2013

      Member

      bpo-18686 have a script which demonstrates the proposed feature.

      However Guilherme's patch is a little wrong. Here is updated patch.

      Note that even this patch is not absolute correct, because Tk adds count if new name is not unique. I.e. if .bpo-12345 already exists it try .bpo-123451, .bpo-123452, .bpo-123453, etc. It is impossible restore original name in general case.

    10. terryjreedy commented on Jul 21, 2016

      Member

      Serhiy, if you are sure your patch is an improvement, then I think you should commit it without waiting for perfection.

      Only the other hand, bpo-18686 does not demonstrate a problem *to me* as it does not fail for me. Does anyone else reproduce the failure on a current non-Windows system? Based just on what I can see, I would be inclined to close this.

    11. serhiy-storchaka commented on Jul 24, 2016

      Member

      bpo-18686 is reproducible to me. Here is a script based on bpo-18686 example. Run it and open the "File" menu.

      $ python3 issue18686.py 
      .#3069298188.#3069298188#3069298252
      Exception in Tkinter callback
      Traceback (most recent call last):
        File "/usr/lib/python3.5/tkinter/__init__.py", line 1553, in __call__
          return self.func(*args)
        File "issue18686.py", line 24, in entry_focus_lost
          widget_with_focus = self.focus_get()
        File "/usr/lib/python3.5/tkinter/__init__.py", line 550, in focus_get
          return self._nametowidget(name)
        File "/usr/lib/python3.5/tkinter/__init__.py", line 1204, in nametowidget
          w = w.children[n]
      KeyError: '#3069298188'

      But my patch doesn't help in case of tearoff menu. Detach the "File" menu and hover a mouse on its item.

      $ ./python issue18686.py 
      .#`menu.#`menu#`menu
      .`menu.`menu
      .tearoff1
      Exception in Tkinter callback
      Traceback (most recent call last):
        File "/home/serhiy/py/cpython/Lib/tkinter/__init__.py", line 1712, in __call__
          return self.func(*args)
        File "issue18686.py", line 24, in entry_focus_lost
          widget_with_focus = self.focus_get()
        File "/home/serhiy/py/cpython/Lib/tkinter/__init__.py", line 692, in focus_get
          return self._nametowidget(name)
        File "/home/serhiy/py/cpython/Lib/tkinter/__init__.py", line 1344, in nametowidget
          w = w.children[n]
      KeyError: 'tearoff1'
    12. 1 remaining item

    13. added
      type-bugAn unexpected behavior, bug, or error
      and removed
      type-featureA feature request or enhancement
      on Jul 24, 2016
    14. terryjreedy commented on Jul 9, 2021

      Member

      See bpo-44592, closed as duplicate of this.

    15. transferred this issue fromon Apr 9, 2022
    16. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Nov 23, 2023
    17. ashm-dev commented on Nov 13, 2025

      Contributor

      Ping. Is this issue still relevant?

    18. sharktide commented on Apr 10, 2026

      Contributor

      No activity. Should we close as not planned?

    19. added a commit that references this issue on Jun 26, 2026
    20. serhiy-storchaka commented on Jun 26, 2026

      Member

      Fixed by GH-152336. nametowidget() now maps the auto-generated name of a cloned menu (a menu used as a menubar or a cascade) back to the original widget instead of raising KeyError.

      This resolves the menu-clone case specifically. The more general fix — letting nametowidget() return a wrapper for any existing Tcl widget (including tear-offs and foreign widgets) by adopting it on its pathname — would subsume this special-casing, and is left as future work.

    21. added 3 commits that reference this issue on Jun 26, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directorytopic-tkintertype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions


        Back | FazBrowse Home | New Git URL