
- Tcl Tutorial
- Tcl - Home
- Tcl - Overview
- Tcl - Environment Setup
- Tcl - Special Variables
- Tcl - Basic Syntax
- Tcl - Commands
- Tcl - Data Types
- Tcl - Variables
- Tcl - Operators
- Tcl - Decisions
- Tcl - Loops
- Tcl - Arrays
- Tcl - Strings
- Tcl - Lists
- Tcl - Dictionary
- Tcl - Procedures
- Tcl - Packages
- Tcl - Namespaces
- Tcl - File I/O
- Tcl - Error Handling
- Tcl - Built-in Functions
- Tcl - Regular Expressions
- Tk Tutorial
- Tk - Overview
- Tk - Environment
- Tk - Special Variables
- Tk - Widgets Overview
- Tk - Basic Widgets
- Tk - Layout Widgets
- Tk - Selection Widgets
- Tk - Canvas Widgets
- Tk - Mega Widgets
- Tk - Fonts
- Tk - Images
- Tk - Events
- Tk - Windows Manager
- Tk - Geometry Manager
- Tcl/Tk Useful Resources
- Tcl/Tk - Quick Guide
- Tcl/Tk - Useful Resources
- Tcl/Tk - Discussion
Tk - Text Widget
Tk text widget is a general purpose editable text widget with features for multiple options. The syntax for text widget is shown below −
text textName options
Options
The options available for the text widget are listed below in table −
Sr.No. | Syntax & Description |
---|---|
1 | -background color Used to set background color for widget. |
2 | -borderwidth width Used to draw with border in 3D effects. |
3 | -font fontDescriptor Used to set font for widget. |
4 | -foreground color Used to set foreground color for widget. |
5 | -relief condition Sets the 3D relief for this widget. The condition may be raised, sunken, flat, ridge, solid, or groove. |
6 | -width number Sets the width for widget. |
7 | -height number Used to set height for widget. |
A simple example for text widget is shown below −
#!/usr/bin/wish grid [text .myText -background red -foreground white -relief ridge -borderwidth 8 -padx 10 -pady 10 -font {Helvetica -18 bold} -width 20 -height 5] .myText insert 1.0 "Hello\nWorld\n" .myText insert end "A new line\n" .myText tag configure para -spacing1 0.15i -spacing2 0.05i \ -lmargin1 0.25i -lmargin2 0.2i -rmargin 0.25i .myText tag configure hang -lmargin1 0.30i -lmargin2 0.25i .myText tag add para 1.0 2.end .myText tag add hang 3.0 3.end
When we run the above program, we will get the following output −

As you can see, text widgets works with the help of procedures like tag, insert, and delete. Most of the tag usages have been covered in the above example.