Skip to content

Commit 1deea5e

Browse files
j4321serhiy-storchaka
authored andcommitted
bpo-34936: Fix TclError in tkinter.Spinbox.selection_element(). (GH-9760)
1 parent bbd90e4 commit 1deea5e

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

Lib/tkinter/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4280,25 +4280,25 @@ def selection_adjust(self, index):
42804280
select to commands. If the selection isn't currently in
42814281
the spinbox, then a new selection is created to include
42824282
the characters between index and the most recent selection
4283-
anchor point, inclusive. Returns an empty string.
4283+
anchor point, inclusive.
42844284
"""
42854285
return self.selection("adjust", index)
42864286

42874287
def selection_clear(self):
42884288
"""Clear the selection
42894289
42904290
If the selection isn't in this widget then the
4291-
command has no effect. Returns an empty string.
4291+
command has no effect.
42924292
"""
42934293
return self.selection("clear")
42944294

42954295
def selection_element(self, element=None):
42964296
"""Sets or gets the currently selected element.
42974297
42984298
If a spinbutton element is specified, it will be
4299-
displayed depressed
4299+
displayed depressed.
43004300
"""
4301-
return self.selection("element", element)
4301+
return self.tk.call(self._w, 'selection', 'element', element)
43024302

43034303
def selection_from(self, index):
43044304
"""Set the fixed end of a selection to INDEX."""

Lib/tkinter/test/test_tkinter/test_widgets.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,14 @@ def test_selection_methods(self):
522522
self.assertEqual(widget.selection_get(), '2345')
523523
widget.selection_adjust(0)
524524
self.assertEqual(widget.selection_get(), '12345')
525-
widget.selection_adjust(0)
525+
526+
def test_selection_element(self):
527+
widget = self.create()
528+
self.assertEqual(widget.selection_element(), "none")
529+
widget.selection_element("buttonup")
530+
self.assertEqual(widget.selection_element(), "buttonup")
531+
widget.selection_element("buttondown")
532+
self.assertEqual(widget.selection_element(), "buttondown")
526533

527534

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