Skip to content

Commit f0ed293

Browse files
chrstphrchvzterryjreedyblurb-it[bot]
authored
gh-103685: Fix tkinter.Menu.index() for Tk 8.7 (#103686)
--------- 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 bd2dca0 commit f0ed293

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Lib/test/test_tkinter/test_widgets.py

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

1380+
def test_indexcommand_none(self):
1381+
widget = self.create()
1382+
i = widget.index('none')
1383+
self.assertIsNone(i)
1384+
13801385
def test_configure_postcommand(self):
13811386
widget = self.create()
13821387
self.checkCommandParam(widget, 'postcommand')

Lib/tkinter/__init__.py

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

34363435
def invoke(self, index):
34373436
"""Invoke a menu item identified by INDEX and execute
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)