gh-97928: Partially restore the behavior of tkinter.Text.count() by default (GH-115031)

By default, it preserves an inconsistent behavior of older Python
versions: packs the count into a 1-tuple if only one or none
options are specified (including 'update'), returns None instead of 0.
Except that setting wantobjects to 0 no longer affects the result.

Add a new parameter return_ints: specifying return_ints=True makes
Text.count() always returning the single count as an integer
instead of a 1-tuple or None.
This commit is contained in:
Serhiy Storchaka 2024-02-11 12:43:14 +02:00 committed by GitHub
parent 5d2794a16b
commit d2c4baa41f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 59 additions and 28 deletions

View file

@ -27,7 +27,7 @@ def get_displaylines(text, index):
"""Display height, in lines, of a logical line in a Tk text widget."""
return text.count(f"{index} linestart",
f"{index} lineend",
"displaylines")
"displaylines", return_ints=True)
def get_widget_padding(widget):
"""Get the total padding of a Tk widget, including its border."""