mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[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:
parent
5054459678
commit
dc08c7a515
3 changed files with 7 additions and 2 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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')
|
||||||
|
|
|
||||||
|
|
@ -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``.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue