diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-10-24 09:59:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-24 09:59:19 (GMT) |
commit | b8c20f90492f9ef2c4600e2739f8e871a31b93c3 (patch) | |
tree | 7e0fb6e73a73903d62a347039806fb9f1eb42919 /Lib/tkinter | |
parent | 81eba7645082a192c027e739b8eb99a94b4c0eec (diff) | |
download | cpython-b8c20f90492f9ef2c4600e2739f8e871a31b93c3.zip cpython-b8c20f90492f9ef2c4600e2739f8e871a31b93c3.tar.gz cpython-b8c20f90492f9ef2c4600e2739f8e871a31b93c3.tar.bz2 |
gh-97928: Change the behavior of tkinter.Text.count() (GH-98484)
It now always returns an integer if one or less counting options are specified.
Previously it could return a single count as a 1-tuple, an integer (only if
option "update" was specified) or None if no items found.
The result is now the same if wantobjects is set to 0.
Diffstat (limited to 'Lib/tkinter')
-rw-r--r-- | Lib/tkinter/__init__.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 440e7f1..47b93d3 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -3715,25 +3715,28 @@ class Text(Widget, XView, YView): return self.tk.getboolean(self.tk.call( self._w, 'compare', index1, op, index2)) - def count(self, index1, index2, *args): # new in Tk 8.5 + def count(self, index1, index2, *options): # new in Tk 8.5 """Counts the number of relevant things between the two indices. - If index1 is after index2, the result will be a negative number + + If INDEX1 is after INDEX2, the result will be a negative number (and this holds for each of the possible options). - The actual items which are counted depends on the options given by - args. The result is a list of integers, one for the result of each - counting option given. Valid counting options are "chars", + The actual items which are counted depends on the options given. + The result is a tuple of integers, one for the result of each + counting option given, if more than one option is specified, + otherwise it is an integer. Valid counting options are "chars", "displaychars", "displayindices", "displaylines", "indices", - "lines", "xpixels" and "ypixels". There is an additional possible + "lines", "xpixels" and "ypixels". The default value, if no + option is specified, is "indices". There is an additional possible option "update", which if given then all subsequent options ensure that any possible out of date information is recalculated.""" - args = ['-%s' % arg for arg in args] - args += [index1, index2] - res = self.tk.call(self._w, 'count', *args) or None - if res is not None and len(args) <= 3: - return (res, ) - else: - return res + options = ['-%s' % arg for arg in options] + res = self.tk.call(self._w, 'count', *options, index1, index2) + if not isinstance(res, int): + res = self._getints(res) + if len(res) == 1: + res, = res + return res def debug(self, boolean=None): """Turn on the internal consistency checks of the B-Tree inside the text |