[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 f0ed293f6a)

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>
This commit is contained in:
Miss Islington (bot) 2023-04-23 19:29:58 -07:00 committed by GitHub
parent 5054459678
commit dc08c7a515
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View file

@ -3429,8 +3429,7 @@ def entryconfigure(self, index, cnf=None, **kw):
def index(self, index): def index(self, index):
"""Return the index of a menu item identified by INDEX.""" """Return the index of a menu item identified by INDEX."""
i = self.tk.call(self._w, 'index', index) i = self.tk.call(self._w, 'index', index)
if i == 'none': return None return None if i in ('', 'none') else self.tk.getint(i) # GH-103685.
return self.tk.getint(i)
def invoke(self, index): def invoke(self, index):
"""Invoke a menu item identified by INDEX and execute """Invoke a menu item identified by INDEX and execute

View file

@ -1378,6 +1378,11 @@ class MenuTest(AbstractWidgetTest, unittest.TestCase):
def create(self, **kwargs): def create(self, **kwargs):
return tkinter.Menu(self.root, **kwargs) return tkinter.Menu(self.root, **kwargs)
def test_indexcommand_none(self):
widget = self.create()
i = widget.index('none')
self.assertIsNone(i)
def test_configure_postcommand(self): def test_configure_postcommand(self):
widget = self.create() widget = self.create()
self.checkCommandParam(widget, 'postcommand') self.checkCommandParam(widget, 'postcommand')

View file

@ -0,0 +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``.