[Python-checkins] [2.7] bpo-34936: Fix TclError in tkinter.Spinbox.selection_element(). (GH-9760) (GH-9957) (GH-9968)

Serhiy Storchaka webhook-mailer at python.org
Sun Oct 21 03:10:27 EDT 2018


https://github.com/python/cpython/commit/427b8c7f7dcdbff21de78b10d9ad05c825480618
commit: 427b8c7f7dcdbff21de78b10d9ad05c825480618
branch: 2.7
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2018-10-21T10:10:24+03:00
summary:

[2.7] bpo-34936: Fix TclError in tkinter.Spinbox.selection_element(). (GH-9760) (GH-9957) (GH-9968)

(cherry picked from commit 1deea5e53991b46351f6bb395b22365c9455ed88).
(cherry picked from commit bd9c2ce7acaef45f23c2659b854fc9925096d040)

Co-authored-by: Juliette Monsel <j4321 at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2018-10-08-21-05-11.bpo-34936.3tRqdq.rst
M Lib/lib-tk/Tkinter.py
M Lib/lib-tk/test/test_tkinter/test_widgets.py

diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py
index 2f3a3f12a512..6c02955928ec 100644
--- a/Lib/lib-tk/Tkinter.py
+++ b/Lib/lib-tk/Tkinter.py
@@ -3582,7 +3582,7 @@ def selection_adjust(self, index):
         select to commands. If the selection isn't currently in
         the spinbox, then a new selection is created to include
         the characters between index and the most recent selection
-        anchor point, inclusive. Returns an empty string.
+        anchor point, inclusive.
         """
         return self.selection("adjust", index)
 
@@ -3590,7 +3590,7 @@ def selection_clear(self):
         """Clear the selection
 
         If the selection isn't in this widget then the
-        command has no effect. Returns an empty string.
+        command has no effect.
         """
         return self.selection("clear")
 
@@ -3598,9 +3598,9 @@ def selection_element(self, element=None):
         """Sets or gets the currently selected element.
 
         If a spinbutton element is specified, it will be
-        displayed depressed
+        displayed depressed.
         """
-        return self.selection("element", element)
+        return self.tk.call(self._w, 'selection', 'element', element)
 
 ###########################################################################
 
diff --git a/Lib/lib-tk/test/test_tkinter/test_widgets.py b/Lib/lib-tk/test/test_tkinter/test_widgets.py
index db2cd9db2430..4b196ac5d510 100644
--- a/Lib/lib-tk/test/test_tkinter/test_widgets.py
+++ b/Lib/lib-tk/test/test_tkinter/test_widgets.py
@@ -471,6 +471,14 @@ def test_bbox(self):
         self.assertRaises(TypeError, widget.bbox)
         self.assertRaises(TypeError, widget.bbox, 0, 1)
 
+    def test_selection_element(self):
+        widget = self.create()
+        self.assertEqual(widget.selection_element(), "none")
+        widget.selection_element("buttonup")
+        self.assertEqual(widget.selection_element(), "buttonup")
+        widget.selection_element("buttondown")
+        self.assertEqual(widget.selection_element(), "buttondown")
+
 
 @add_standard_options(StandardOptionsTests)
 class TextTest(AbstractWidgetTest, unittest.TestCase):
diff --git a/Misc/NEWS.d/next/Library/2018-10-08-21-05-11.bpo-34936.3tRqdq.rst b/Misc/NEWS.d/next/Library/2018-10-08-21-05-11.bpo-34936.3tRqdq.rst
new file mode 100644
index 000000000000..7c1f7bb59760
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-10-08-21-05-11.bpo-34936.3tRqdq.rst
@@ -0,0 +1,2 @@
+Fix ``TclError`` in ``tkinter.Spinbox.selection_element()``. Patch by
+Juliette Monsel.



More information about the Python-checkins mailing list