Skip to content

gh-135658: Add documentation for tkinter.Text widget#146467

Open
SHAHID-glitch wants to merge 1 commit intopython:mainfrom
SHAHID-glitch:docs-tkinter-text
Open

gh-135658: Add documentation for tkinter.Text widget#146467
SHAHID-glitch wants to merge 1 commit intopython:mainfrom
SHAHID-glitch:docs-tkinter-text

Conversation

@SHAHID-glitch
Copy link

@SHAHID-glitch SHAHID-glitch commented Mar 26, 2026

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/

Copilot AI review requested due to automatic review settings March 26, 2026 15:01
@bedevere-app bedevere-app bot added docs Documentation in the Doc dir skip news awaiting review labels Mar 26, 2026
@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Mar 26, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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*.
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
Delete text between *index1* and *index2*.
Delete text between *index1* and *index2*. If *index2* is omitted,
deletes the character at *index1*.

Copilot uses AI. Check for mistakes.
Comment on lines +1049 to +1050
The :class:`tkinter.Text` widget can contain other widgets, such as buttons or images,
embedded directly within the text flow.
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.
Embedded widgets
----------------

The :class:`tkinter.Text` widget can contain other widgets, such as buttons or images,
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“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.

Suggested change
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,

Copilot uses AI. Check for mistakes.
Comment on lines +1010 to +1019
.. 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)
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
.. 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)

Copilot uses AI. Check for mistakes.
Comment on lines +1004 to +1006
* ``"end"`` – the end of the text
* ``"insert"`` – the current insertion cursor position

Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
* ``"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

Copilot uses AI. Check for mistakes.
is ``line.column``, where *line* and *column* are integers starting from
1 and 0 respectively.

Indexes can also include symbolic names.
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.
@SHAHID-glitch SHAHID-glitch changed the title Add documentation for tkinter.Text widget gh-135658: Add documentation for tkinter.Text widget Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants