Skip to content

Commit 427b8c7

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

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Lib/lib-tk/Tkinter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,25 +3582,25 @@ def selection_adjust(self, index):
35823582
select to commands. If the selection isn't currently in
35833583
the spinbox, then a new selection is created to include
35843584
the characters between index and the most recent selection
3585-
anchor point, inclusive. Returns an empty string.
3585+
anchor point, inclusive.
35863586
"""
35873587
return self.selection("adjust", index)
35883588

35893589
def selection_clear(self):
35903590
"""Clear the selection
35913591
35923592
If the selection isn't in this widget then the
3593-
command has no effect. Returns an empty string.
3593+
command has no effect.
35943594
"""
35953595
return self.selection("clear")
35963596

35973597
def selection_element(self, element=None):
35983598
"""Sets or gets the currently selected element.
35993599
36003600
If a spinbutton element is specified, it will be
3601-
displayed depressed
3601+
displayed depressed.
36023602
"""
3603-
return self.selection("element", element)
3603+
return self.tk.call(self._w, 'selection', 'element', element)
36043604

36053605
###########################################################################
36063606

Lib/lib-tk/test/test_tkinter/test_widgets.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,14 @@ def test_bbox(self):
471471
self.assertRaises(TypeError, widget.bbox)
472472
self.assertRaises(TypeError, widget.bbox, 0, 1)
473473

474+
def test_selection_element(self):
475+
widget = self.create()
476+
self.assertEqual(widget.selection_element(), "none")
477+
widget.selection_element("buttonup")
478+
self.assertEqual(widget.selection_element(), "buttonup")
479+
widget.selection_element("buttondown")
480+
self.assertEqual(widget.selection_element(), "buttondown")
481+
474482

475483
@add_standard_options(StandardOptionsTests)
476484
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)