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.
This commit is contained in:
Serhiy Storchaka 2023-10-24 12:59:19 +03:00 committed by GitHub
parent 81eba76450
commit b8c20f9049
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 55 deletions

View file

@ -25,10 +25,9 @@ def get_end_linenumber(text):
def get_displaylines(text, index):
"""Display height, in lines, of a logical line in a Tk text widget."""
res = text.count(f"{index} linestart",
f"{index} lineend",
"displaylines")
return res[0] if res else 0
return text.count(f"{index} linestart",
f"{index} lineend",
"displaylines")
def get_widget_padding(widget):
"""Get the total padding of a Tk widget, including its border."""