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=Noneclosed_at=Nonecreated_at=<Date2003-05-07.20:11:52.000>labels= ['type-bug', 'expert-tkinter']
title="Make Tkinter.py's nametowidget work with cloned menu widgets"updated_at=<Date2021-07-09.21:02:53.288>user='https://bugs.python.org/gregcouch'
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.
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.
gpolo commented on Dec 31, 2008
gpolomannequin
Mannequin
More actions
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.
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.
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.
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__returnself.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_getreturnself._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__returnself.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_getreturnself._nametowidget(name)
File "/home/serhiy/py/cpython/Lib/tkinter/__init__.py", line 1344, in nametowidget
w = w.children[n]
KeyError: 'tearoff1'
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.
Activity
gregcouch commented on May 7, 2003
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.
jepler commented on May 11, 2003
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.
gpolo commented on Dec 31, 2008
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.
BreamoreBoy commented on Aug 18, 2010
A small simple patch that I see no problems with.
abalkin commented on Aug 18, 2010
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.
BreamoreBoy commented on May 19, 2013
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.
gregcouch commented on May 20, 2013
We still apply that patch to the Python that we embed in our application
and have for the last 10 years :-)
BreamoreBoy commented on May 20, 2013
I've attached a patch for Python 3 which I hope is okay as it's my first attempt using TortoiseHg on Windows.
serhiy-storchaka commented on Aug 22, 2013
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.
terryjreedy commented on Jul 21, 2016
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.
serhiy-storchaka commented on Jul 24, 2016
bpo-18686 is reproducible to me. Here is a script based on bpo-18686 example. Run it and open the "File" menu.
But my patch doesn't help in case of tearoff menu. Detach the "File" menu and hover a mouse on its item.
1 remaining item
terryjreedy commented on Jul 9, 2021
See bpo-44592, closed as duplicate of this.
ashm-dev commented on Nov 13, 2025
Ping. Is this issue still relevant?
sharktide commented on Apr 10, 2026
No activity. Should we close as not planned?
gh-38464: Make tkinter nametowidget() work with cloned menus (GH-152336)
serhiy-storchaka commented on Jun 26, 2026
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.
[3.13] gh-38464: Make tkinter nametowidget() work with cloned menus (G…
[3.14] gh-38464: Make tkinter nametowidget() work with cloned menus (G…
[3.15] gh-38464: Make tkinter nametowidget() work with cloned menus (G…