1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
3
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
5
<title>GCL TK Manual: Common Features of Widgets</title>
7
<meta name="description" content="GCL TK Manual: Common Features of Widgets">
8
<meta name="keywords" content="GCL TK Manual: Common Features of Widgets">
9
<meta name="resource-type" content="document">
10
<meta name="distribution" content="global">
11
<meta name="Generator" content="makeinfo">
12
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
13
<link href="index.html#Top" rel="start" title="Top">
14
<link href="wm.html#SEC_Contents" rel="contents" title="Table of Contents">
15
<link href="General.html#General" rel="up" title="General">
16
<link href="Return-Values.html#Return-Values" rel="next" title="Return Values">
17
<link href="Getting-Started.html#Getting-Started" rel="prev" title="Getting Started">
18
<style type="text/css">
20
a.summary-letter {text-decoration: none}
21
blockquote.smallquotation {font-size: smaller}
22
div.display {margin-left: 3.2em}
23
div.example {margin-left: 3.2em}
24
div.indentedblock {margin-left: 3.2em}
25
div.lisp {margin-left: 3.2em}
26
div.smalldisplay {margin-left: 3.2em}
27
div.smallexample {margin-left: 3.2em}
28
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
29
div.smalllisp {margin-left: 3.2em}
30
kbd {font-style:oblique}
31
pre.display {font-family: inherit}
32
pre.format {font-family: inherit}
33
pre.menu-comment {font-family: serif}
34
pre.menu-preformatted {font-family: serif}
35
pre.smalldisplay {font-family: inherit; font-size: smaller}
36
pre.smallexample {font-size: smaller}
37
pre.smallformat {font-family: inherit; font-size: smaller}
38
pre.smalllisp {font-size: smaller}
39
span.nocodebreak {white-space:nowrap}
40
span.nolinebreak {white-space:nowrap}
41
span.roman {font-family:serif; font-weight:normal}
42
span.sansserif {font-family:sans-serif; font-weight:normal}
43
ul.no-bullet {list-style: none}
50
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
51
<a name="Common-Features-of-Widgets"></a>
54
Next: <a href="Return-Values.html#Return-Values" accesskey="n" rel="next">Return Values</a>, Previous: <a href="Getting-Started.html#Getting-Started" accesskey="p" rel="prev">Getting Started</a>, Up: <a href="General.html#General" accesskey="u" rel="up">General</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
57
<a name="Common-Features-of-Widgets-1"></a>
58
<h3 class="section">1.3 Common Features of Widgets</h3>
60
<p>A <i>widget</i> is a lisp symbol which has a function binding. The
61
first argument is always a keyword and is called the <i>option</i>.
62
The argument pattern for the remaining arguments depends on the
63
<i>option</i>. The most common <i>option</i> is <code>:configure</code> in
64
which case the remaining arguments are alternating keyword/value
65
pairs, with the same keywords being permitted as at the creation
68
<p>A <i>widget</i> is created by means of a <i>widget constructor</i>, of
69
which there are currently 15, each of them appearing as the title of a
70
section in <a href="Widgets.html#Widgets">Widgets</a>. They live in the <code>"TK"</code> package, and for
71
the moment we will assume we have switched to this package. Thus for
72
example <code>button</code> is such a widget constructor function. Of course
73
this is lisp, and you can make your own widget constructors, but when
74
you do so it is a good idea to follow the standard argument patterns
75
that are outlined in this section.
78
<pre class="example">(button '.hello)
81
<p>creates a <i>widget</i> whose name is <code>.hello</code>. There is a parent child
82
hierarchy among widgets which is implicit in the name used for the
83
widget. This is much like the pathname structure on a Unix or Dos
84
file system, except that <code>'.'</code> is used as the separator rather
85
than a <code>/</code> or <code>\</code>. For this reason the widget instances
86
are sometimes referred to as <i>pathnames</i>. A child of the
87
parent widget <code>.hello</code> might be called <code>.hello.joe</code>, and
88
a child of this last might be <code>.hello.joe.bar</code>. The parent of
89
everyone is called <code>.</code> . Multiple top level windows are created
90
using the <code>toplevel</code> command (see <a href="toplevel.html#toplevel">toplevel</a>).
92
<p>The widget constructor functions take keyword and value pairs, which
93
allow you to specify attributes at the time of creation:
96
<pre class="example">(button '.hello :text "Hello World" :width 20)
99
<p>indicating that we want the text in the button window to be
100
<code>Hello World</code> and the width of the window to be 20 characters
101
wide. Other types of windows allow specification in centimeters
102
<code>2c</code>, or in inches (<code>2i</code>) or in millimeters <code>2m</code>
103
or in pixels <code>2</code>. But text windows usually have their
104
dimensions specified as multiples of a character width and height.
105
This latter concept is called a grid.
107
<p>Once the window has been created, if you want to change the
109
</p><div class="example">
110
<pre class="example">(button '.hello :text "Bye World" :width 20)
112
<p>This would be in error, because the window .hello already exists.
113
You would either have to first call
115
<div class="example">
116
<pre class="example">(destroy '.hello)
119
<p>But usually you just want to change an attribute. <code>.hello</code> is
120
actually a function, as we mentioned earlier, and it is this function
123
<div class="example">
124
<pre class="example">(.hello :configure :text "Bye World")
127
<p>This would simply change the text, and not change where the window had
128
been placed on the screen (if it had), or how it had been packed
129
into the window hierarchy. Here the argument <code>:configure</code> is
130
called an <i>option</i>, and it specifies which types of keywords can
131
follow it. For example
133
<div class="example">
134
<pre class="example">(.hello :flash)
136
<p>is also valid, but in this case the <code>:text</code> keyword is not permitted
137
after flash. If it were, then it would mean something else besides
138
what it means in the above. For example one might have defined
140
<div class="example">
141
<pre class="example">(.hello :flash :text "PUSH ME")
143
<p>so here the same keyword <code>:text</code> would mean something else, eg
144
to flash a subliminal message on the screen.
146
<p>We often refer to calls to the widget functions
147
as messages. One reason for this is that they actually turn into
148
messages to the graphics process <samp>gcltksrv</samp>. To actually see these
150
</p><div class="example">
151
<pre class="example">(debugging t).
157
Next: <a href="Return-Values.html#Return-Values" accesskey="n" rel="next">Return Values</a>, Previous: <a href="Getting-Started.html#Getting-Started" accesskey="p" rel="prev">Getting Started</a>, Up: <a href="General.html#General" accesskey="u" rel="up">General</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>