Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 320f339

Browse files
Issue #6167: Scrollbar.activate() now returns the name of active element if
the argument is not specified. Scrollbar.set() now always accepts only 2 arguments. Added tests for Scrollbar.activate() and Scrollbar.set().
1 parent 6e20460 commit 320f339

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

Lib/tkinter/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,10 +2875,14 @@ def __init__(self, master=None, cnf={}, **kw):
28752875
relief, repeatdelay, repeatinterval, takefocus,
28762876
troughcolor, width."""
28772877
Widget.__init__(self, master, 'scrollbar', cnf, kw)
2878-
def activate(self, index):
2879-
"""Display the element at INDEX with activebackground and activerelief.
2880-
INDEX can be "arrow1","slider" or "arrow2"."""
2881-
self.tk.call(self._w, 'activate', index)
2878+
def activate(self, index=None):
2879+
"""Marks the element indicated by index as active.
2880+
The only index values understood by this method are "arrow1",
2881+
"slider", or "arrow2". If any other value is specified then no
2882+
element of the scrollbar will be active. If index is not specified,
2883+
the method returns the name of the element that is currently active,
2884+
or None if no element is active."""
2885+
return self.tk.call(self._w, 'activate', index) or None
28822886
def delta(self, deltax, deltay):
28832887
"""Return the fractional change of the scrollbar setting if it
28842888
would be moved by DELTAX or DELTAY pixels."""
@@ -2896,10 +2900,10 @@ def get(self):
28962900
"""Return the current fractional values (upper and lower end)
28972901
of the slider position."""
28982902
return self._getdoubles(self.tk.call(self._w, 'get'))
2899-
def set(self, *args):
2903+
def set(self, first, last):
29002904
"""Set the fractional values of the slider position (upper and
29012905
lower ends as value between 0 and 1)."""
2902-
self.tk.call((self._w, 'set') + args)
2906+
self.tk.call(self._w, 'set', first, last)
29032907

29042908

29052909

Lib/tkinter/test/test_tkinter/test_widgets.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,25 @@ def test_orient(self):
916916
self.checkEnumParam(widget, 'orient', 'vertical', 'horizontal',
917917
errmsg='bad orientation "{}": must be vertical or horizontal')
918918

919+
def test_activate(self):
920+
sb = self.create()
921+
for e in ('arrow1', 'slider', 'arrow2'):
922+
sb.activate(e)
923+
self.assertEqual(sb.activate(), e)
924+
sb.activate('')
925+
self.assertIsNone(sb.activate())
926+
self.assertRaises(TypeError, sb.activate, 'arrow1', 'arrow2')
927+
928+
def test_set(self):
929+
sb = self.create()
930+
sb.set(0.2, 0.4)
931+
self.assertEqual(sb.get(), (0.2, 0.4))
932+
self.assertRaises(TclError, sb.set, 'abc', 'def')
933+
self.assertRaises(TclError, sb.set, 0.6, 'def')
934+
self.assertRaises(TclError, sb.set, 0.6, None)
935+
self.assertRaises(TypeError, sb.set, 0.6)
936+
self.assertRaises(TypeError, sb.set, 0.6, 0.7, 0.8)
937+
919938

920939
@add_standard_options(StandardOptionsTests)
921940
class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ Core and Builtins
108108
Library
109109
-------
110110

111+
- Issue #6167: Scrollbar.activate() now returns the name of active element if
112+
the argument is not specified. Scrollbar.set() now always accepts only 2
113+
arguments.
114+
111115
- Issue #15275: Clean up and speed up the ntpath module.
112116

113117
- Issue #21888: plistlib's load() and loads() now work if the fmt parameter is

0 commit comments

Comments
 (0)