- 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 - Canvas Text Widget
Canvas text widget is used to draw text in canvas. The syntax for canvas text widget is shown below −
canvasName create text x y options
x and y are used to determine the position of text −
Options
The options available for the canvas text widget are listed below in the following table −
Sr.No. | Syntax & Description |
---|---|
1 | -anchor position The text will be positioned relative to the x and y locations. Center is default and other options are n, s, e, w, ne, se, sw, and nw. |
2 | -justify style Determines the multiline, should be right justified, left justified, or center justified. The default is left. |
3 | -fill color The fill color fills the oval with the color. |
4 | -text text The text for text widget. |
5 | -font fontStyle The font to use for this text. |
A simple example for canvas text widget is shown below −
#!/usr/bin/wish canvas .myCanvas -background red -width 200 -height 200 pack .myCanvas .myCanvas create text 100 100 -fill yellow -justify center -text "Hello World.\n How are you?" -font {Helvetica -18 bold}
When we run the above program, we will get the following output −