Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

tkinter.Text.count(index1, index2) returns None not (0,) when index1 equals index2 #97928

Closed
Assignees
serhiy-storchaka
Labels
@RogerMarsh

Description

@RogerMarsh

Surely the Text.count() method should return (0,) in the title code snippet? Following the example of what happens when more than one option is given.

I suppose the text_count method should do so too, but it was a hack of something that did not exist when written.

Tk8.6 documentation says a list of integers is returned.

Sample code below.

importtkinterdeftext_count(widget,index1,index2,*options):"""Hack Text count command. Return integer, or tuple if len(options) > 1.    Tkinter does not provide a wrapper for the Tk Text widget count command    at Python 2.7.1    widget is a Tkinter Text widget.    index1 and index2 are Indicies as specified in TkCmd documentation.    options must be a tuple of zero or more option values.  If no options    are given the Tk default option is used.  If less than two options are    given an integer is returned.  Otherwise a tuple of integers is returned    (in the order specified in TkCmd documentation).    See text manual page in TkCmd documentation for valid option values and    index specification.    Example:    chars, lines = text_count(widget, start, end, '-chars', '-lines')    """returnwidget.tk.call((widget._w,'count')+options+ (index1,index2))text=tkinter.Text()print(text.count("1.0",tkinter.END))# (1,0)print(text.count("1.0","1.0"))# Noneprint(text_count(text,"1.0","1.0"))# 0print(text_count(text,"1.0",tkinter.END))# 1print(text.count("1.0",tkinter.END,"chars"))# (1,)print(text.count("1.0","1.0","chars"))# Noneprint(text_count(text,"1.0","1.0","-chars"))# 0print(text_count(text,"1.0",tkinter.END,"-chars"))# 1print(text.count(tkinter.END,"1.0","chars"))# (-1,)print(text_count(text,tkinter.END,"1.0","-chars"))# -1print(text.count("1.0",tkinter.END,"chars","lines"))# (1, 1)print(text.count("1.0","1.0","chars","lines"))# (0, 0)print(text_count(text,"1.0","1.0","-chars","-lines"))# (0, 0)print(text_count(text,"1.0",tkinter.END,"-chars","-lines"))# (1, 1)

Linked PRs

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp