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