21ee096cbe8e2a10a4a669a48a08be7e23783241
[msysgit.git] / mingw / lib / tk8.5 / demos / text.tcl
blob21ee096cbe8e2a10a4a669a48a08be7e23783241
1 # text.tcl --
3 # This demonstration script creates a text widget that describes
4 # the basic editing functions.
6 if {![info exists widgetDemo]} {
7 error "This script should be run from the \"widget\" demo."
10 package require Tk
12 set w .text
13 catch {destroy $w}
14 toplevel $w
15 wm title $w "Text Demonstration - Basic Facilities"
16 wm iconname $w "text"
17 positionWindow $w
19 ## See Code / Dismiss buttons
20 set btns [addSeeDismiss $w.buttons $w]
21 pack $btns -side bottom -fill x
23 text $w.text -yscrollcommand [list $w.scroll set] -setgrid 1 \
24 -height 30 -undo 1 -autosep 1
25 scrollbar $w.scroll -command [list $w.text yview]
26 pack $w.scroll -side right -fill y
27 pack $w.text -expand yes -fill both
28 $w.text insert 0.0 \
29 {This window is a text widget. It displays one or more lines of text
30 and allows you to edit the text. Here is a summary of the things you
31 can do to a text widget:
33 1. Scrolling. Use the scrollbar to adjust the view in the text window.
35 2. Scanning. Press mouse button 2 in the text window and drag up or down.
36 This will drag the text at high speed to allow you to scan its contents.
38 3. Insert text. Press mouse button 1 to set the insertion cursor, then
39 type text. What you type will be added to the widget.
41 4. Select. Press mouse button 1 and drag to select a range of characters.
42 Once you've released the button, you can adjust the selection by pressing
43 button 1 with the shift key down. This will reset the end of the
44 selection nearest the mouse cursor and you can drag that end of the
45 selection by dragging the mouse before releasing the mouse button.
46 You can double-click to select whole words or triple-click to select
47 whole lines.
49 5. Delete and replace. To delete text, select the characters you'd like
50 to delete and type Backspace or Delete. Alternatively, you can type new
51 text, in which case it will replace the selected text.
53 6. Copy the selection. To copy the selection into this window, select
54 what you want to copy (either here or in another application), then
55 click button 2 to copy the selection to the point of the mouse cursor.
57 7. Edit. Text widgets support the standard Motif editing characters
58 plus many Emacs editing characters. Backspace and Control-h erase the
59 character to the left of the insertion cursor. Delete and Control-d
60 erase the character to the right of the insertion cursor. Meta-backspace
61 deletes the word to the left of the insertion cursor, and Meta-d deletes
62 the word to the right of the insertion cursor. Control-k deletes from
63 the insertion cursor to the end of the line, or it deletes the newline
64 character if that is the only thing left on the line. Control-o opens
65 a new line by inserting a newline character to the right of the insertion
66 cursor. Control-t transposes the two characters on either side of the
67 insertion cursor. Control-z undoes the last editing action performed,
68 and }
70 switch $tcl_platform(platform) {
71 "unix" {
72 $w.text insert end "Control-Shift-z"
74 "windows" {
75 $w.text insert end "Control-y"
79 $w.text insert end { redoes undone edits.
81 7. Resize the window. This widget has been configured with the "setGrid"
82 option on, so that if you resize the window it will always resize to an
83 even number of characters high and wide. Also, if you make the window
84 narrow you can see that long lines automatically wrap around onto
85 additional lines so that all the information is always visible.}
86 $w.text mark set insert 0.0