Text Widget Methods
The Text widget supports the standard Tkinter base Widget interface along with the following specialized method operations for layout stream control, coordinate processing, asset mounting, and contextual rendering logic.
Standard Core API Methods
Appends a text stream at the specified index target location (commonly INSERT or END symbols). If optional tags values are configured, the layout framework attaches style meta parameters directly across the newly evaluated character array elements.
If text coordinates resolve exactly directly atop an explicit structural mark, the target reference pointer increments forward or shifts depending upon current gravity configurations.
Deletes the single item block element (such as a character token or embedded container element) located at the exact index, or clears all content spans encapsulated inside the designated start and stop range boundaries. Any internal persistent text pointers and marks located within the targets collapse into the start coordinate point.
Retrieves a raw python string representation of the textual token matching the singular coordinate location, or returns an absolute text array sequence contained between the explicit start and stop coordinates.
Returns an analytical structural dump tracking meta components inside the layout engine for a coordinate or range. The object output contains specific token designations for all elements including formatting tags, absolute placement marks, and runtime window or image structures.
Forces vertical window viewport adjustments to make hidden text sequences fully visible on screen. Calling see() updates positions minimally only if the targeted segment is outside the current view bounds, while yview() explicitly overrides scrolling offsets to instantly frame the chosen coordinate line right at the topmost row of the viewport area.
Normalizes expressions, relative strings, and floating cursor indicators into a canonical "line.column" formatted string identifier representation.
Evaluates spatial relationships between two structural coordinate points. Returns a boolean truth flag confirming matching or positional variations. Valid op parameters accept standard string evaluations: "<", "<=", "==", ">=", ">", or "!=".
Methods for Marks
Use the following operational interfaces to construct, relocate, or delete custom and native reference pointer marks within the text buffer layer matrix.
Relocates a designated named mark tracking pointer directly onto a new absolute text target coordinate block position. If the requested lookup tag doesn't exist, the engine creates it natively, defaulting tracking behavior flags to RIGHT gravity. This programmatic interface manages built-in runtime layout variables like INSERT and CURRENT selectors.
Deletes a tracking pointer mark reference identifier out of the active engine memory tables. Built-in layout tracking markers like INSERT or CURRENT are core infrastructure layers and cannot be deleted.
Gets or overrides gravity mechanics rules (accepting string literals LEFT or RIGHT) applied to a selected text marker. Gravity controls tracking directions when a stream update splits exactly atop the marker pointer. Setting LEFT retains historical boundaries (new strings stream immediately past the reference), whereas setting RIGHT snaps tracking forward alongside the text layout extension array. The global engine standard defaults directly to RIGHT rules.
Returns a comprehensive python tuple string list tracking all custom and default internal system indicators configured inside the active window space, excluding structural boundary tags like END.
Methods for Embedded Windows
Embedded sub-windows consume exactly one discrete sequential spatial slot position. Mounted component frames flow sequentially alongside raw characters inside the multi-line typographical engine layout.
Mounts an external executable UI container directly inside the rendering surface array loop structure. Developers can supply predefined widget instances configured as explicit layout children using the window argument, or define a lazy rendering generation interface callback string trigger bound to the create pipeline.
Text Window Configuration Options
| Option | Type | Description |
|---|---|---|
| align | constant | Defines vertical row balance distribution frameworks. Values include TOP, CENTER, BOTTOM, or BASELINE (snapping container bases evenly matching string characters text run baselines). |
| create | callback | Configures a runtime generator function triggered dynamically during initial layout processing steps. Must instantiate a child widget component and return the new object model reference. |
| padx, pady | distance | Defines pixel buffer clearance margins separating the element border edges directly away from outer typographic content grids. |
| stretch | flag | When enabled (ON / 1), forces the component height limits to scale dynamically matching line block capacities, overriding alignment definitions. |
| window | widget | Sets the pre-existing target widget structural reference object slated for deployment into the text interface area block map. |
Inspects or updates stylistic configuration parameter values assigned to an embedded control instance at a specific position. Throws a TclError if no widget object matches the location index query.
Returns a flat list tracker tuple containing references to all active nested sub-widgets within the text view array matrix workspace.
Methods for Embedded Images
Natively renders pixel graphic buffers directly on inline rows. Mounted images occupy exactly one text coordinate token space and adapt dynamically matching text buffer flow behaviors.
Mounts a graphics object instance directly inside the rendering matrix grid. The graphics instance must map to a valid PhotoImage, BitmapImage, or equivalent structural canvas instance from the Python Imaging Library (PIL).
Text Image Configuration Options
| Option | Type | Description |
|---|---|---|
| align | constant | Controls vertical integration vectors for image lines: TOP, CENTER, BOTTOM, or BASELINE. |
| image | image object | Points to the target image reference slated for deployment into the text interface area block map. |
| name | string | Sets a unique structural access token string lookup identifier used when targeting operations on the embedded graphic asset element. |
| padx, pady | distance | Applies protective spatial clearing distance gaps surrounding asset graphic layout boundaries. |
Queries or modifies option configurations for an embedded graphic component at the specified position coordinate lookup. Throws a TclError runtime exception if no asset matches the index.
Returns a compilation tracker tracking named string keys matching every active embedded pixel graphic mounted inside the text workspace area layout grid matrix.
Methods for Style Tags
Tags apply custom contextual behavior, stylistic properties, and interaction overrides across discrete ranges of text inside the widget layer core.
Binds a named string identifier meta tag directly across a single character position, or registers a span boundary block ranging between start and stop metrics.
Strips out specified tag style assignments off the matched position or target content span range. Core properties bound to the structural styling tag persist intact inside engine tables for future operations.
Completely deletes a tag from the widget's internal configuration tables. This drops all graphic rendering layouts and structural event bindings linked to that tag across the active canvas layout canvas surface.
Configures typographic rendering rules for a tag. If the tag name is missing from the active engine, the engine instantiates it as a new style rule layer. Multiple overlapping tags combine their properties, with settings from tags higher up the processing stack taking priority.
Attaches mouse, keyboard, or viewport trigger callbacks directly onto a styled text block segment. Using an optional plus symbol parameter ("+") appends new programmatic execution logic blocks onto existing callback functions rather than clearing older execution states.
Scans the content array forwards or backwards starting from a specified position index to locate the boundaries of the nearest matching tag segment range block.
Adjusts stack layer ordering priority levels for styling tags. This reorders evaluation cascades when multiple tags overlap on a single text run segment block.
Methods for Selections
The Text widget manages highlight behaviors using the internal system styling tag SEL, rather than through standalone dedicated interface components. You can implement custom selection management workflows using standard core tag methods:
def selection_clear(text_widget):
# Clears all highlight boundaries off the selection tracker tag
text_widget.tag_remove("sel", "1.0", "end")
def selection_present(text_widget):
# Verifies if text highlight components are present inside the view
return len(text_widget.tag_ranges("sel")) != 0
def selection_range(text_widget, start_index, end_index):
# Updates the active text highlight block across exact layout bounds
text_widget.tag_remove("sel", "1.0", start_index)
text_widget.tag_add("sel", start_index, end_index)
text_widget.tag_remove("sel", end_index, "end")
Geometry and Layout Metrics Methods
These methods calculate physical pixel dimension details relative to the visible workspace layout canvas screen area. Always verify that structural paint calls are complete by invoking update_idletasks() before accessing these geometry metrics methods.
Calculates exact relative bounding coordinates for a character token position. Returns a 4-item tuple tracking screen parameters: (x, y, width, height). Returns None if the character position falls outside the visible viewport area bounds.
Returns display metrics data tracking the entire rendering line block containing the targeted index character token. Output formats map out to a 5-item tuple tracker array: (x, y, width, height, baseline_offset). Returns None if the row is hidden from view.
Search and Pattern Filtering Methods
Scans text buffer fields for matching content patterns. Returns the absolute string index of the first match position, or an empty string indicator if the pattern is not found.
Text Search Options
| Option | Type | Description |
|---|---|---|
| forwards, backwards | flag | Sets the directional processing track relative to the start index: scanning toward the end of the buffer file (forwards) or scrolling backward toward the top of the file (backwards). |
| chars, lines | distance | Defines scanning search limit distance profiles inside individual text block configurations. |
| exact, regexp | flag | Toggles the pattern matching mode. exact performs simple literal string matching, while regexp evaluates queries as standard Tcl regular expressions. |
| nocase | flag | When enabled, strips out font casing constraints to execute case-insensitive search matching. |
| stopindex | index | Defines a strict end boundary for search operations. If omitted, the engine wraps around the entire document until it returns to the starting index point. |