1
#!/usr/local/bin/perl -w
6
my $top = MainWindow->new;
7
$top->option('add','*Text.background'=>'white');
9
my $t = $top->Scrolled('Text',"-relief" => "raised",
11
"-setgrid" => "true");
14
$m->add("command", "-label" => "Open", "-underline" => 0,
15
"-command" => \&sayopen);
16
$m->add("command", "-label" => "Close", "-underline" => 0,
17
"-command" => \&sayclose);
19
$m->add("command", "-label" => "Selection", "-underline" => 0,
20
"-command" => \&showsel);
22
$m->add("command", "-label" => "Exit", "-underline" => 1,
23
"-command" => \&doexit);
25
$t->pack(-expand => 1, "-fill" => "both");
27
$t->tag("configure", "underline","-underline","on");
28
$t->tag("configure", "hideable", -elide => 0, -foreground => 'blue');
30
$t->insert("0.0", "This window is a text widget. It displays one or more
31
lines of text and allows you to edit the text. Here is a summary of the
32
things you can do to a text widget:",'hideable');
36
1. Insert text. Press mouse button 1 to set the insertion cursor, then
37
type text. What you type will be added to the widget. You can backspace
38
over what you've typed using either the backspace key, the delete key,
41
2. Resize the window. This widget has been configured with the \"setGrid\"
42
option on, so that if you resize the window it will always resize to an
43
even number of characters high and wide. Also, if you make the window
44
narrow you can see that long lines automatically wrap around onto
45
additional lines so that all the information is always visible.
47
3. Scanning. Press mouse button 2 in the text window and drag up or down.
48
This will drag the text at high speed to allow you to scan its contents.
50
4. Select. Press mouse button 1 and drag to select a range of characters.
51
Once you've released the button, you can adjust the selection by pressing
52
button 1 with the shift key down. This will reset the end of the
53
selection nearest the mouse cursor and you can drag that end of the
54
selection by dragging the mouse before releasing the mouse button.
55
You can double-click to select whole words, or triple-click to select
58
5. Delete. To delete text, select the characters you'd like to delete
61
6. Copy the selection. To copy the selection either from this window
62
or from any other window or application, select what you want, click
63
button 1 to set the insertion cursor, then type Control+v to copy the
64
selection to the point of the insertion cursor.
66
You can also bind commands to tags. Like press button 3 for menu ");
68
&insertwtag($t,"here","underline");
70
$t->tag("bind","underline","<3>", [sub { shift; shift->Post(@_)},$m,Ev(X),Ev(Y)] );
72
$t->bind("<Any-Enter>", sub { $t->focus });
74
$t->Subwidget('text')->OnDestroy(sub { print "Destroyed!\n"; print $t->get('1.0','end') });
76
$t->tag("bind", "hideable","<2>", sub {
77
$t->tagConfigure(hideable => -elide => 1, -foreground => 'pink')}
84
local($w,$text,$tag) = @_;
85
my $start = $w->index("insert");
86
print "start=$start\n";
87
$w->insert("insert",$text);
88
$w->tag("add",$tag,$start,"insert");
92
sub sayopen { print "Open something\n" }
93
sub sayclose { print "Close something\n" }
94
sub showsel { my @info = $t->tagRanges('sel');
97
print "start=$info[0] end=$info[1]\n"
102
die "'die' no longer exits"