gh-135658: Add documentation for tkinter.Text widget#146467
gh-135658: Add documentation for tkinter.Text widget#146467SHAHID-glitch wants to merge 1 commit intopython:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new documentation section to Doc/library/tkinter.rst describing the tkinter.Text widget, aiming to fill a gap in Tkinter widget documentation within the standard library docs.
Changes:
- Introduces a new “Text” section with basic usage and index concepts.
- Documents core text operations (insert/get/delete) plus tags, marks, embedding, and undo/redo basics.
- Adds an explicit reference target for linking to the new section.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| .. method:: delete(index1, index2=None) | ||
|
|
||
| Delete text between *index1* and *index2*. |
There was a problem hiding this comment.
delete(index1, index2=None): the text says it deletes “between index1 and index2”, but doesn’t describe the index2-omitted behavior. For Text.delete(index1) this deletes a single character at index1; documenting that would make this method description accurate and consistent with the preceding get description.
| Delete text between *index1* and *index2*. | |
| Delete text between *index1* and *index2*. If *index2* is omitted, | |
| deletes the character at *index1*. |
| The :class:`tkinter.Text` widget can contain other widgets, such as buttons or images, | ||
| embedded directly within the text flow. |
There was a problem hiding this comment.
The line describing embedded widgets is quite long and exceeds the line-wrapping style used throughout this document. Please wrap it to match the surrounding reST formatting (typically ~79–80 columns) so future diffs stay readable.
| The :class:`tkinter.Text` widget can contain other widgets, such as buttons or images, | |
| embedded directly within the text flow. | |
| The :class:`tkinter.Text` widget can contain other widgets, such as buttons | |
| or images, embedded directly within the text flow. |
| Embedded widgets | ||
| ---------------- | ||
|
|
||
| The :class:`tkinter.Text` widget can contain other widgets, such as buttons or images, |
There was a problem hiding this comment.
“Embedded widgets” example text mixes widgets and images (“widgets, such as buttons or images”). In Tk terminology, images aren’t widgets; they’re embedded via image handling APIs. Consider rephrasing to distinguish embedding windows (widgets) vs embedding images, to avoid conceptual confusion.
| The :class:`tkinter.Text` widget can contain other widgets, such as buttons or images, | |
| The :class:`tkinter.Text` widget can contain other widgets, such as buttons, |
| .. method:: insert(index, chars, *args) | ||
|
|
||
| Insert *chars* at the given *index*. | ||
|
|
||
| .. method:: get(index1, index2=None) | ||
|
|
||
| Return the text between *index1* and *index2*. If *index2* is omitted, | ||
| returns the character at *index1*. | ||
|
|
||
| .. method:: delete(index1, index2=None) |
There was a problem hiding this comment.
The new .. method:: directives are unqualified (e.g., just insert/get/delete). In this file, method directives are otherwise qualified (e.g., Widget.tk.createfilehandler), and unqualified method targets are likely to create ambiguous index entries / weak cross-references. Consider qualifying these (e.g., Text.insert or tkinter.Text.insert) or introducing a .. class:: Text directive and indenting the methods under it so Sphinx can associate them with the class.
| .. method:: insert(index, chars, *args) | |
| Insert *chars* at the given *index*. | |
| .. method:: get(index1, index2=None) | |
| Return the text between *index1* and *index2*. If *index2* is omitted, | |
| returns the character at *index1*. | |
| .. method:: delete(index1, index2=None) | |
| .. method:: Text.insert(index, chars, *args) | |
| Insert *chars* at the given *index*. | |
| .. method:: Text.get(index1, index2=None) | |
| Return the text between *index1* and *index2*. If *index2* is omitted, | |
| returns the character at *index1*. | |
| .. method:: Text.delete(index1, index2=None) |
| * ``"end"`` – the end of the text | ||
| * ``"insert"`` – the current insertion cursor position | ||
|
|
There was a problem hiding this comment.
The description of the "end" index as “the end of the text” is a bit misleading for Text widgets: Tk text widgets maintain a trailing newline, so using end commonly includes an extra newline and users often need end-1c (or similar) to exclude it. It would be helpful to mention this nuance in the index examples.
| * ``"end"`` – the end of the text | |
| * ``"insert"`` – the current insertion cursor position | |
| * ``"end"`` – the position just after the last character (for :class:`Text` | |
| widgets this is after the trailing newline, so use ``"end-1c"`` to exclude it) | |
| * ``"insert"`` – the current insertion cursor position |
| is ``line.column``, where *line* and *column* are integers starting from | ||
| 1 and 0 respectively. | ||
|
|
||
| Indexes can also include symbolic names. |
There was a problem hiding this comment.
This new section adds a concrete description of Text indexes, but earlier in the same “The index Parameter” section there is still a paragraph saying Text widget index notation is “best described in the Tk man pages.” Consider updating that earlier paragraph to link to this new “Text” section (or trimming it) to avoid contradictory guidance.
| Indexes can also include symbolic names. | |
| Indexes can also include symbolic names. This section provides a brief | |
| overview; for a complete description of text index syntax, see the Tk | |
| :manpage:`text(n)` manual page. |
Adds documentation for tkinter.Text widget.
It Includes:
Basic usage
Index system
Core methods (insert, get, delete)
Tags and formatting
Marks
Embedded widgets
Undo/redo support
These addresses missing documentation for tkinter.Text
📚 Documentation preview 📚: https://cpython-previews--146467.org.readthedocs.build/
tkinter.textis not documented #135658