Skip to content

Commit dc08c7a

Browse files
miss-islingtonchrstphrchvzterryjreedyblurb-it[bot]
authoredApr 24, 2023
[3.11] gh-103685: Fix tkinter.Menu.index() for Tk 8.7 (GH-103686) (#103734)
gh-103685: Fix tkinter.Menu.index() for Tk 8.7 (GH-103686) --------- (cherry picked from commit f0ed293) Co-authored-by: Christopher Chavez <chrischavez@gmx.us> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
1 parent 5054459 commit dc08c7a

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed
 

‎Lib/tkinter/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3429,8 +3429,7 @@ def entryconfigure(self, index, cnf=None, **kw):
34293429
def index(self, index):
34303430
"""Return the index of a menu item identified by INDEX."""
34313431
i = self.tk.call(self._w, 'index', index)
3432-
if i == 'none': return None
3433-
return self.tk.getint(i)
3432+
return None if i in ('', 'none') else self.tk.getint(i) # GH-103685.
34343433

34353434
def invoke(self, index):
34363435
"""Invoke a menu item identified by INDEX and execute

‎Lib/tkinter/test/test_tkinter/test_widgets.py

+5
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,11 @@ class MenuTest(AbstractWidgetTest, unittest.TestCase):
13781378
def create(self, **kwargs):
13791379
return tkinter.Menu(self.root, **kwargs)
13801380

1381+
def test_indexcommand_none(self):
1382+
widget = self.create()
1383+
i = widget.index('none')
1384+
self.assertIsNone(i)
1385+
13811386
def test_configure_postcommand(self):
13821387
widget = self.create()
13831388
self.checkCommandParam(widget, 'postcommand')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prepare :meth:`tkinter.Menu.index` for Tk 8.7 so that it does not raise ``TclError: expected integer but got ""`` when it should return ``None``.

0 commit comments

Comments
 (0)
Please sign in to comment.