Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="tkinter-basic-mapping.html" /> | |
13 | <link rel="prev" href="node716.html" /> | |
14 | <link rel="parent" href="module-Tkinter.html" /> | |
15 | <link rel="next" href="tkinter-basic-mapping.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>16.1.3 A (Very) Quick Look at Tcl/Tk</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="16.1.2.2 A Simple Hello" | |
25 | href="node718.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="16.1 Tkinter " | |
28 | href="module-Tkinter.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="16.1.4 Mapping Basic Tk" | |
31 | href="tkinter-basic-mapping.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="node718.html">16.1.2.2 A Simple Hello</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="module-Tkinter.html">16.1 Tkinter </A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="tkinter-basic-mapping.html">16.1.4 Mapping Basic Tk</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION0018130000000000000000"> | |
56 | 16.1.3 A (Very) Quick Look at Tcl/Tk</A> | |
57 | </H2> | |
58 | <P> | |
59 | The class hierarchy looks complicated, but in actual practice, | |
60 | application programmers almost always refer to the classes at the very | |
61 | bottom of the hierarchy. | |
62 | ||
63 | <P> | |
64 | Notes: | |
65 | ||
66 | <UL> | |
67 | <LI>These classes are provided for the purposes of | |
68 | organizing certain functions under one namespace. They aren't meant to | |
69 | be instantiated independently. | |
70 | ||
71 | <P> | |
72 | </LI> | |
73 | <LI>The <tt class="class">Tk</tt> class is meant to be instantiated only once in | |
74 | an application. Application programmers need not instantiate one | |
75 | explicitly, the system creates one whenever any of the other classes | |
76 | are instantiated. | |
77 | ||
78 | <P> | |
79 | </LI> | |
80 | <LI>The <tt class="class">Widget</tt> class is not meant to be instantiated, it | |
81 | is meant only for subclassing to make ``real'' widgets (in C++, this | |
82 | is called an `abstract class'). | |
83 | </LI> | |
84 | </UL> | |
85 | ||
86 | <P> | |
87 | To make use of this reference material, there will be times when you | |
88 | will need to know how to read short passages of Tk and how to identify | |
89 | the various parts of a Tk command. | |
90 | (See section <A href="tkinter-basic-mapping.html#tkinter-basic-mapping">16.1.4</A> for the | |
91 | <tt class="module"><a href="module-Tkinter.html">Tkinter</a></tt> equivalents of what's below.) | |
92 | ||
93 | <P> | |
94 | Tk scripts are Tcl programs. Like all Tcl programs, Tk scripts are | |
95 | just lists of tokens separated by spaces. A Tk widget is just its | |
96 | <em>class</em>, the <em>options</em> that help configure it, and the | |
97 | <em>actions</em> that make it do useful things. | |
98 | ||
99 | <P> | |
100 | To make a widget in Tk, the command is always of the form: | |
101 | ||
102 | <P> | |
103 | <div class="verbatim"><pre> | |
104 | classCommand newPathname options | |
105 | </pre></div> | |
106 | ||
107 | <P> | |
108 | <DL> | |
109 | <DT><STRONG><var>classCommand</var></STRONG></DT> | |
110 | <DD>denotes which kind of widget to make (a button, a label, a menu...) | |
111 | ||
112 | <P> | |
113 | </DD> | |
114 | <DT><STRONG><var>newPathname</var></STRONG></DT> | |
115 | <DD>is the new name for this widget. All names in Tk must be unique. To | |
116 | help enforce this, widgets in Tk are named with <em>pathnames</em>, just | |
117 | like files in a file system. The top level widget, the <em>root</em>, | |
118 | is called <code>.</code> (period) and children are delimited by more | |
119 | periods. For example, <code>.myApp.controlPanel.okButton</code> might be | |
120 | the name of a widget. | |
121 | ||
122 | <P> | |
123 | </DD> | |
124 | <DT><STRONG><var>options</var> </STRONG></DT> | |
125 | <DD>configure the widget's appearance and in some cases, its | |
126 | behavior. The options come in the form of a list of flags and values. | |
127 | Flags are proceeded by a `-', like unix shell command flags, and | |
128 | values are put in quotes if they are more than one word. | |
129 | </DD> | |
130 | </DL> | |
131 | ||
132 | <P> | |
133 | For example: | |
134 | ||
135 | <P> | |
136 | <div class="verbatim"><pre> | |
137 | button .fred -fg red -text "hi there" | |
138 | ^ ^ \_____________________/ | |
139 | | | | | |
140 | class new options | |
141 | command widget (-opt val -opt val ...) | |
142 | </pre></div> | |
143 | ||
144 | <P> | |
145 | Once created, the pathname to the widget becomes a new command. This | |
146 | new <var>widget command</var> is the programmer's handle for getting the new | |
147 | widget to perform some <var>action</var>. In C, you'd express this as | |
148 | someAction(fred, someOptions), in C++, you would express this as | |
149 | fred.someAction(someOptions), and in Tk, you say: | |
150 | ||
151 | <P> | |
152 | <div class="verbatim"><pre> | |
153 | .fred someAction someOptions | |
154 | </pre></div> | |
155 | ||
156 | <P> | |
157 | Note that the object name, <code>.fred</code>, starts with a dot. | |
158 | ||
159 | <P> | |
160 | As you'd expect, the legal values for <var>someAction</var> will depend on | |
161 | the widget's class: <code>.fred disable</code> works if fred is a | |
162 | button (fred gets greyed out), but does not work if fred is a label | |
163 | (disabling of labels is not supported in Tk). | |
164 | ||
165 | <P> | |
166 | The legal values of <var>someOptions</var> is action dependent. Some | |
167 | actions, like <code>disable</code>, require no arguments, others, like | |
168 | a text-entry box's <code>delete</code> command, would need arguments | |
169 | to specify what range of text to delete. | |
170 | ||
171 | <P> | |
172 | ||
173 | <DIV CLASS="navigation"> | |
174 | <div class='online-navigation'> | |
175 | <p></p><hr /> | |
176 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
177 | <tr> | |
178 | <td class='online-navigation'><a rel="prev" title="16.1.2.2 A Simple Hello" | |
179 | href="node718.html"><img src='../icons/previous.png' | |
180 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
181 | <td class='online-navigation'><a rel="parent" title="16.1 Tkinter " | |
182 | href="module-Tkinter.html"><img src='../icons/up.png' | |
183 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
184 | <td class='online-navigation'><a rel="next" title="16.1.4 Mapping Basic Tk" | |
185 | href="tkinter-basic-mapping.html"><img src='../icons/next.png' | |
186 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
187 | <td align="center" width="100%">Python Library Reference</td> | |
188 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
189 | href="contents.html"><img src='../icons/contents.png' | |
190 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
191 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
192 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
193 | <td class='online-navigation'><a rel="index" title="Index" | |
194 | href="genindex.html"><img src='../icons/index.png' | |
195 | border='0' height='32' alt='Index' width='32' /></A></td> | |
196 | </tr></table> | |
197 | <div class='online-navigation'> | |
198 | <b class="navlabel">Previous:</b> | |
199 | <a class="sectref" rel="prev" href="node718.html">16.1.2.2 A Simple Hello</A> | |
200 | <b class="navlabel">Up:</b> | |
201 | <a class="sectref" rel="parent" href="module-Tkinter.html">16.1 Tkinter </A> | |
202 | <b class="navlabel">Next:</b> | |
203 | <a class="sectref" rel="next" href="tkinter-basic-mapping.html">16.1.4 Mapping Basic Tk</A> | |
204 | </div> | |
205 | </div> | |
206 | <hr /> | |
207 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
208 | </DIV> | |
209 | <!--End of Navigation Panel--> | |
210 | <ADDRESS> | |
211 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
212 | </ADDRESS> | |
213 | </BODY> | |
214 | </HTML> |