bpo-34936: Fix TclError in tkinter.Spinbox.selection_element(). (GH-9… · python/cpython@bd9c2ce (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -3750,25 +3750,25 @@ def selection_adjust(self, index):
3750 3750 select to commands. If the selection isn't currently in
3751 3751 the spinbox, then a new selection is created to include
3752 3752 the characters between index and the most recent selection
3753 - anchor point, inclusive. Returns an empty string.
3753 + anchor point, inclusive.
3754 3754 """
3755 3755 return self.selection("adjust", index)
3756 3756
3757 3757 def selection_clear(self):
3758 3758 """Clear the selection
3759 3759
3760 3760 If the selection isn't in this widget then the
3761 - command has no effect. Returns an empty string.
3761 + command has no effect.
3762 3762 """
3763 3763 return self.selection("clear")
3764 3764
3765 3765 def selection_element(self, element=None):
3766 3766 """Sets or gets the currently selected element.
3767 3767
3768 3768 If a spinbutton element is specified, it will be
3769 - displayed depressed
3769 + displayed depressed.
3770 3770 """
3771 -return self.selection("element", element)
3771 +return self.tk.call(self._w, 'selection', 'element', element)
3772 3772
3773 3773 ###########################################################################
3774 3774
Original file line number Diff line number Diff line change
@@ -474,6 +474,14 @@ def test_bbox(self):
474 474 self.assertRaises(TypeError, widget.bbox)
475 475 self.assertRaises(TypeError, widget.bbox, 0, 1)
476 476
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 +
477 485
478 486 @add_standard_options(StandardOptionsTests)
479 487 class TextTest(AbstractWidgetTest, unittest.TestCase):
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 +Fix ``TclError`` in ``tkinter.Spinbox.selection_element()``. Patch by
2 +Juliette Monsel.