- Tcl - Regular Expressions
- Tcl - Built-in Functions
- Tcl - Error Handling
- Tcl - File I/O
- Tcl - Namespaces
- Tcl - Packages
- Tcl - Procedures
- Tcl - Dictionary
- Tcl - Lists
- Tcl - Strings
- Tcl - Arrays
- Tcl - Loops
- Tcl - Decisions
- Tcl - Operators
- Tcl - Variables
- Tcl - Data Types
- Tcl - Commands
- Tcl - Basic Syntax
- Tcl - Special Variables
- Tcl - Environment Setup
- Tcl - Overview
- Tcl - Home
Tk Tutorial
- Tk - Geometry Manager
- Tk - Windows Manager
- Tk - Events
- Tk - Images
- Tk - Fonts
- Tk - Mega Widgets
- Tk - Canvas Widgets
- Tk - Selection Widgets
- Tk - Layout Widgets
- Tk - Basic Widgets
- Tk - Widgets Overview
- Tk - Special Variables
- Tk - Environment
- Tk - Overview
Tcl/Tk Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Tk - Canvas Widgets
Canvas is used for providing drawing areas. The syntax for canvas widget is shown below −
canvas canvasName options
Options
The options available for the canvas widget are psted below in the following table −
Sr.No. | Syntax & Description |
---|---|
1 | -background color Used to set background color for widget. |
2 | -closeenough distance Sets the closeness of mouse cursor to a displayable item. The default is 1.0 pixel. This value may be a fraction and must be positive. |
3 | -scrollregion boundingBox The bounding box for the total area of this canvas. |
4 | -height number Used to set height for widget. |
5 | -width number Sets the width for widget. |
6 | -xscrolpncrement size The amount to scroll horizontally when scrolpng is requested. |
7 | -yscrolpncrement size The amount to scroll vertically when scrolpng is requested. |
A simple example for canvas widget is shown below −
#!/usr/bin/wish canvas .myCanvas -background red -width 100 -height 100 pack .myCanvas
When we run the above program, we will get the following output −
Widgets for Drawing in Canvas
The pst of the available widgets for drawing in canvas is psted below −
Sr.No. | Widget & Description |
---|---|
1 | Draws a pne. |
2 | Draws an arc. |
3 | Draws a rectangle. |
4 | Draws an oval. |
5 | Draws a polygon. |
6 | Draws a text. |
7 | Draws a bitmap. |
8 | Draws an image. |
An example using different canvas widgets is shown below −
#!/usr/bin/wish canvas .myCanvas -background red -width 200 -height 200 pack .myCanvas .myCanvas create arc 10 10 50 50 -fill yellow .myCanvas create pne 10 30 50 50 100 10 -arrow both -fill yellow -smooth true -sppnesteps 2 .myCanvas create oval 50 50 100 80 -fill yellow .myCanvas create polygon 50 150 100 80 120 120 100 190 -fill yellow -outpne green .myCanvas create rectangle 150 150 170 170 -fill yellow .myCanvas create text 170 20 -fill yellow -text "Hello" -font {Helvetica -18 bold} .myCanvas create bitmap 180 50 -bitmap info
When we run the above program, we will get the following output −
Advertisements