Skip to content

Commit c04347f

Browse files
bpo-34936: Fix TclError in tkinter.Spinbox.selection_element(). (GH-9760) (GH-9957)
(cherry picked from commit 1deea5e) (cherry picked from commit bd9c2ce) Co-authored-by: Juliette Monsel <[email protected]>
1 parent 322a914 commit c04347f

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Lib/tkinter/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3750,25 +3750,25 @@ def selection_adjust(self, index):
37503750
select to commands. If the selection isn't currently in
37513751
the spinbox, then a new selection is created to include
37523752
the characters between index and the most recent selection
3753-
anchor point, inclusive. Returns an empty string.
3753+
anchor point, inclusive.
37543754
"""
37553755
return self.selection("adjust", index)
37563756

37573757
def selection_clear(self):
37583758
"""Clear the selection
37593759
37603760
If the selection isn't in this widget then the
3761-
command has no effect. Returns an empty string.
3761+
command has no effect.
37623762
"""
37633763
return self.selection("clear")
37643764

37653765
def selection_element(self, element=None):
37663766
"""Sets or gets the currently selected element.
37673767
37683768
If a spinbutton element is specified, it will be
3769-
displayed depressed
3769+
displayed depressed.
37703770
"""
3771-
return self.selection("element", element)
3771+
return self.tk.call(self._w, 'selection', 'element', element)
37723772

37733773
###########################################################################
37743774

Lib/tkinter/test/test_tkinter/test_widgets.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,14 @@ def test_bbox(self):
474474
self.assertRaises(TypeError, widget.bbox)
475475
self.assertRaises(TypeError, widget.bbox, 0, 1)
476476

477+
def test_selection_element(self):
478+
widget = self.create()
479+
self.assertEqual(widget.selection_element(), "none")
480+
widget.selection_element("buttonup")
481+
self.assertEqual(widget.selection_element(), "buttonup")
482+
widget.selection_element("buttondown")
483+
self.assertEqual(widget.selection_element(), "buttondown")
484+
477485

478486
@add_standard_options(StandardOptionsTests)
479487
class TextTest(AbstractWidgetTest, unittest.TestCase):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``TclError`` in ``tkinter.Spinbox.selection_element()``. Patch by
2+
Juliette Monsel.

0 commit comments

Comments
 (0)