Previous
Menubutton, Menu 
Next
Dialogs 
Tcl/Tk Tutorial - Create GUI using Tk with Tcl Language
Canvas, Message

Some more Widgets - Canvas, Message, Panedwindow, Spinbox

canvas

The canvas widget is a very important widget as all points are addressable graphical drawing area. Canvas widgets implement structured graphics. A canvas displays any number of items, which may be things like rectangles, circles, lines, and text. Items may be manipulated (e.g. moved or re-colored) and commands may be associated with items. So if you don't like the paint program in windows, you can make your own program using this widget.

The command path create type options is used to make different structures. A few examples are given below. For more information read the excellent manual that comes with Tcl/Tk.

Example

canvas .cns -relief sunken -background "blue"
.cns create polygon 5 100   50 5   150 5   200 100   5 100 \
	-joinstyle bevel -fill "red" -outline "white" -width 5
.cns create oval 200 100 300 200 -fill "green"
.cns create oval 100 150 300 100 -fill "white" -width 0
.cns create rectangle 10 150 100 250 -dash {6 4 2 4 2 4}
pack .cns

message

A message is a widget that displays a textual string. Much like the label widget but this can be used to make a multi-line text.

The -justify option specifies how to justify lines of text. Must be one of left, center, or right. Defaults to left. This option works together with the anchor, aspect, padX, padY, and width options to provide a variety of arrangements of the text within the window.


panedwindow

A panedwindow acts like the frame widget - with one notable exception. The borders can be dragged and expended. This widget contains any number of panes, arranged horizontally or vertically, according to the value of the -orient option. Each pane contains one widget, and each pair of panes is separated by a movable sash. Moving a sash can be done by dragging it. This causes the widgets on either side of the sash to be resized.

Some Options
-orient DIRECTIONThis option specifies which orientation should be used. DIRECTION must be either horizontal or vertical or an abbreviation of one of these(h or v).
-opaqueresize BOOLEANSpecifies whether panes should be resized as a sash is moved (true), or if resizing should be deferred until the sash is placed (false).
-increment NUMBERWhen used with -from and -to, the value in the widget will be adjusted by -increment when a spin button is pressed (up adds the value, down subtracts the value). Default 1.

Example
panedwindow .pnd -orient v -opaqueresize 0
listbox .lst
.lst insert end "Item 1"
.lst insert end "Item 2"
.lst insert end "Item 3"
.lst insert end "Item 4"
.lst insert end "Item 5"

text .txt
.txt insert end {To Hack With It

     To Compute...
     Or Not To Compute...
     That Is The Question...
     Whether 'Tis Nobler In The Memory Bank..
     To Suffer The Slings And Circuits Of Outrageous Functions...
     ...Or To Take Up Arms Against A Sea Of..Transistors,
     Or Rather Transponders...
     Transcondu--
     Trans...
     Er...           Oh, To Hack With It.
}

.pnd add .lst
.pnd add .txt
pack .pnd -fill both -expand 1

spinbox

This is widget is like an entry widget with two buttons to the right of it to increase or decrease the number that is displayed in the entry area. See the below example - in which I tried to create a functional entry widget in HTML. Not an exact picture, but the best I can do in HTML. Click on either of the arrows to the right to increase or decrease the number.

^
v

Some Options
-from NUMBERThe starting number. The value in the entry field cannot be reduced below this number.
-to NUMBERNUMBER is the upper limit. The value in the entry field cannot be increased above this number.
-increment NUMBERWhen used with -from and -to, the value in the widget will be adjusted by -increment when a spin button is pressed (up adds the value, down subtracts the value). Default 1.

Example:
set number 5
spinbox .spn -from 1 -to 20 -increment 2 -textvariable number
pack .spn
Previous
Menubutton, Menu 
Next
Dialogs 
Subscribe to Feed