1 | \chapter{Graphical User Interfaces with Tk \label{tkinter}}
|
---|
2 |
|
---|
3 | \index{GUI}
|
---|
4 | \index{Graphical User Interface}
|
---|
5 | \index{Tkinter}
|
---|
6 | \index{Tk}
|
---|
7 |
|
---|
8 | Tk/Tcl has long been an integral part of Python. It provides a robust
|
---|
9 | and platform independent windowing toolkit, that is available to
|
---|
10 | Python programmers using the \refmodule{Tkinter} module, and its
|
---|
11 | extension, the \refmodule{Tix} module.
|
---|
12 |
|
---|
13 | The \refmodule{Tkinter} module is a thin object-oriented layer on top of
|
---|
14 | Tcl/Tk. To use \refmodule{Tkinter}, you don't need to write Tcl code,
|
---|
15 | but you will need to consult the Tk documentation, and occasionally
|
---|
16 | the Tcl documentation. \refmodule{Tkinter} is a set of wrappers that
|
---|
17 | implement the Tk widgets as Python classes. In addition, the internal
|
---|
18 | module \module{\_tkinter} provides a threadsafe mechanism which allows
|
---|
19 | Python and Tcl to interact.
|
---|
20 |
|
---|
21 | Tk is not the only GUI for Python; see
|
---|
22 | section~\ref{other-gui-packages}, ``Other User Interface Modules and
|
---|
23 | Packages,'' for more information on other GUI toolkits for Python.
|
---|
24 |
|
---|
25 | % Other sections I have in mind are
|
---|
26 | % Tkinter internals
|
---|
27 | % Freezing Tkinter applications
|
---|
28 |
|
---|
29 | \localmoduletable
|
---|
30 |
|
---|
31 |
|
---|
32 | \section{\module{Tkinter} ---
|
---|
33 | Python interface to Tcl/Tk}
|
---|
34 |
|
---|
35 | \declaremodule{standard}{Tkinter}
|
---|
36 | \modulesynopsis{Interface to Tcl/Tk for graphical user interfaces}
|
---|
37 | \moduleauthor{Guido van Rossum}{guido@Python.org}
|
---|
38 |
|
---|
39 | The \module{Tkinter} module (``Tk interface'') is the standard Python
|
---|
40 | interface to the Tk GUI toolkit. Both Tk and \module{Tkinter} are
|
---|
41 | available on most \UNIX{} platforms, as well as on Windows and
|
---|
42 | Macintosh systems. (Tk itself is not part of Python; it is maintained
|
---|
43 | at ActiveState.)
|
---|
44 |
|
---|
45 | \begin{seealso}
|
---|
46 | \seetitle[http://www.python.org/topics/tkinter/]
|
---|
47 | {Python Tkinter Resources}
|
---|
48 | {The Python Tkinter Topic Guide provides a great
|
---|
49 | deal of information on using Tk from Python and links to
|
---|
50 | other sources of information on Tk.}
|
---|
51 |
|
---|
52 | \seetitle[http://www.pythonware.com/library/an-introduction-to-tkinter.htm]
|
---|
53 | {An Introduction to Tkinter}
|
---|
54 | {Fredrik Lundh's on-line reference material.}
|
---|
55 |
|
---|
56 | \seetitle[http://www.nmt.edu/tcc/help/pubs/lang.html]
|
---|
57 | {Tkinter reference: a GUI for Python}
|
---|
58 | {On-line reference material.}
|
---|
59 |
|
---|
60 | \seetitle[http://jtkinter.sourceforge.net]
|
---|
61 | {Tkinter for JPython}
|
---|
62 | {The Jython interface to Tkinter.}
|
---|
63 |
|
---|
64 | \seetitle[http://www.amazon.com/exec/obidos/ASIN/1884777813]
|
---|
65 | {Python and Tkinter Programming}
|
---|
66 | {The book by John Grayson (ISBN 1-884777-81-3).}
|
---|
67 | \end{seealso}
|
---|
68 |
|
---|
69 |
|
---|
70 | \subsection{Tkinter Modules}
|
---|
71 |
|
---|
72 | Most of the time, the \refmodule{Tkinter} module is all you really
|
---|
73 | need, but a number of additional modules are available as well. The
|
---|
74 | Tk interface is located in a binary module named \module{_tkinter}.
|
---|
75 | This module contains the low-level interface to Tk, and should never
|
---|
76 | be used directly by application programmers. It is usually a shared
|
---|
77 | library (or DLL), but might in some cases be statically linked with
|
---|
78 | the Python interpreter.
|
---|
79 |
|
---|
80 | In addition to the Tk interface module, \refmodule{Tkinter} includes a
|
---|
81 | number of Python modules. The two most important modules are the
|
---|
82 | \refmodule{Tkinter} module itself, and a module called
|
---|
83 | \module{Tkconstants}. The former automatically imports the latter, so
|
---|
84 | to use Tkinter, all you need to do is to import one module:
|
---|
85 |
|
---|
86 | \begin{verbatim}
|
---|
87 | import Tkinter
|
---|
88 | \end{verbatim}
|
---|
89 |
|
---|
90 | Or, more often:
|
---|
91 |
|
---|
92 | \begin{verbatim}
|
---|
93 | from Tkinter import *
|
---|
94 | \end{verbatim}
|
---|
95 |
|
---|
96 | \begin{classdesc}{Tk}{screenName=None, baseName=None, className='Tk', useTk=1}
|
---|
97 | The \class{Tk} class is instantiated without arguments.
|
---|
98 | This creates a toplevel widget of Tk which usually is the main window
|
---|
99 | of an application. Each instance has its own associated Tcl interpreter.
|
---|
100 | % FIXME: The following keyword arguments are currently recognized:
|
---|
101 | \versionchanged[The \var{useTk} parameter was added]{2.4}
|
---|
102 | \end{classdesc}
|
---|
103 |
|
---|
104 | \begin{funcdesc}{Tcl}{screenName=None, baseName=None, className='Tk', useTk=0}
|
---|
105 | The \function{Tcl} function is a factory function which creates an
|
---|
106 | object much like that created by the \class{Tk} class, except that it
|
---|
107 | does not initialize the Tk subsystem. This is most often useful when
|
---|
108 | driving the Tcl interpreter in an environment where one doesn't want
|
---|
109 | to create extraneous toplevel windows, or where one cannot (such as
|
---|
110 | \UNIX/Linux systems without an X server). An object created by the
|
---|
111 | \function{Tcl} object can have a Toplevel window created (and the Tk
|
---|
112 | subsystem initialized) by calling its \method{loadtk} method.
|
---|
113 | \versionadded{2.4}
|
---|
114 | \end{funcdesc}
|
---|
115 |
|
---|
116 | Other modules that provide Tk support include:
|
---|
117 |
|
---|
118 | \begin{description}
|
---|
119 | % \declaremodule{standard}{Tkconstants}
|
---|
120 | % \modulesynopsis{Constants used by Tkinter}
|
---|
121 | % FIXME
|
---|
122 |
|
---|
123 | \item[\refmodule{ScrolledText}]
|
---|
124 | Text widget with a vertical scroll bar built in.
|
---|
125 |
|
---|
126 | \item[\module{tkColorChooser}]
|
---|
127 | Dialog to let the user choose a color.
|
---|
128 |
|
---|
129 | \item[\module{tkCommonDialog}]
|
---|
130 | Base class for the dialogs defined in the other modules listed here.
|
---|
131 |
|
---|
132 | \item[\module{tkFileDialog}]
|
---|
133 | Common dialogs to allow the user to specify a file to open or save.
|
---|
134 |
|
---|
135 | \item[\module{tkFont}]
|
---|
136 | Utilities to help work with fonts.
|
---|
137 |
|
---|
138 | \item[\module{tkMessageBox}]
|
---|
139 | Access to standard Tk dialog boxes.
|
---|
140 |
|
---|
141 | \item[\module{tkSimpleDialog}]
|
---|
142 | Basic dialogs and convenience functions.
|
---|
143 |
|
---|
144 | \item[\module{Tkdnd}]
|
---|
145 | Drag-and-drop support for \refmodule{Tkinter}.
|
---|
146 | This is experimental and should become deprecated when it is replaced
|
---|
147 | with the Tk DND.
|
---|
148 |
|
---|
149 | \item[\refmodule{turtle}]
|
---|
150 | Turtle graphics in a Tk window.
|
---|
151 |
|
---|
152 | \end{description}
|
---|
153 |
|
---|
154 | \subsection{Tkinter Life Preserver}
|
---|
155 | \sectionauthor{Matt Conway}{}
|
---|
156 | % Converted to LaTeX by Mike Clarkson.
|
---|
157 |
|
---|
158 | This section is not designed to be an exhaustive tutorial on either
|
---|
159 | Tk or Tkinter. Rather, it is intended as a stop gap, providing some
|
---|
160 | introductory orientation on the system.
|
---|
161 |
|
---|
162 | Credits:
|
---|
163 | \begin{itemize}
|
---|
164 | \item Tkinter was written by Steen Lumholt and Guido van Rossum.
|
---|
165 | \item Tk was written by John Ousterhout while at Berkeley.
|
---|
166 | \item This Life Preserver was written by Matt Conway at
|
---|
167 | the University of Virginia.
|
---|
168 | \item The html rendering, and some liberal editing, was
|
---|
169 | produced from a FrameMaker version by Ken Manheimer.
|
---|
170 | \item Fredrik Lundh elaborated and revised the class interface descriptions,
|
---|
171 | to get them current with Tk 4.2.
|
---|
172 | \item Mike Clarkson converted the documentation to \LaTeX, and compiled the
|
---|
173 | User Interface chapter of the reference manual.
|
---|
174 | \end{itemize}
|
---|
175 |
|
---|
176 |
|
---|
177 | \subsubsection{How To Use This Section}
|
---|
178 |
|
---|
179 | This section is designed in two parts: the first half (roughly) covers
|
---|
180 | background material, while the second half can be taken to the
|
---|
181 | keyboard as a handy reference.
|
---|
182 |
|
---|
183 | When trying to answer questions of the form ``how do I do blah'', it
|
---|
184 | is often best to find out how to do``blah'' in straight Tk, and then
|
---|
185 | convert this back into the corresponding \refmodule{Tkinter} call.
|
---|
186 | Python programmers can often guess at the correct Python command by
|
---|
187 | looking at the Tk documentation. This means that in order to use
|
---|
188 | Tkinter, you will have to know a little bit about Tk. This document
|
---|
189 | can't fulfill that role, so the best we can do is point you to the
|
---|
190 | best documentation that exists. Here are some hints:
|
---|
191 |
|
---|
192 | \begin{itemize}
|
---|
193 | \item The authors strongly suggest getting a copy of the Tk man
|
---|
194 | pages. Specifically, the man pages in the \code{mann} directory are most
|
---|
195 | useful. The \code{man3} man pages describe the C interface to the Tk
|
---|
196 | library and thus are not especially helpful for script writers.
|
---|
197 |
|
---|
198 | \item Addison-Wesley publishes a book called \citetitle{Tcl and the
|
---|
199 | Tk Toolkit} by John Ousterhout (ISBN 0-201-63337-X) which is a good
|
---|
200 | introduction to Tcl and Tk for the novice. The book is not
|
---|
201 | exhaustive, and for many details it defers to the man pages.
|
---|
202 |
|
---|
203 | \item \file{Tkinter.py} is a last resort for most, but can be a good
|
---|
204 | place to go when nothing else makes sense.
|
---|
205 | \end{itemize}
|
---|
206 |
|
---|
207 | \begin{seealso}
|
---|
208 | \seetitle[http://tcl.activestate.com/]
|
---|
209 | {ActiveState Tcl Home Page}
|
---|
210 | {The Tk/Tcl development is largely taking place at
|
---|
211 | ActiveState.}
|
---|
212 | \seetitle[http://www.amazon.com/exec/obidos/ASIN/020163337X]
|
---|
213 | {Tcl and the Tk Toolkit}
|
---|
214 | {The book by John Ousterhout, the inventor of Tcl .}
|
---|
215 | \seetitle[http://www.amazon.com/exec/obidos/ASIN/0130220280]
|
---|
216 | {Practical Programming in Tcl and Tk}
|
---|
217 | {Brent Welch's encyclopedic book.}
|
---|
218 | \end{seealso}
|
---|
219 |
|
---|
220 |
|
---|
221 | \subsubsection{A Simple Hello World Program} % HelloWorld.html
|
---|
222 |
|
---|
223 | %begin{latexonly}
|
---|
224 | %\begin{figure}[hbtp]
|
---|
225 | %\centerline{\epsfig{file=HelloWorld.gif,width=.9\textwidth}}
|
---|
226 | %\vspace{.5cm}
|
---|
227 | %\caption{HelloWorld gadget image}
|
---|
228 | %\end{figure}
|
---|
229 | %See also the hello-world \ulink{notes}{classes/HelloWorld-notes.html} and
|
---|
230 | %\ulink{summary}{classes/HelloWorld-summary.html}.
|
---|
231 | %end{latexonly}
|
---|
232 |
|
---|
233 |
|
---|
234 | \begin{verbatim}
|
---|
235 | from Tkinter import *
|
---|
236 |
|
---|
237 | class Application(Frame):
|
---|
238 | def say_hi(self):
|
---|
239 | print "hi there, everyone!"
|
---|
240 |
|
---|
241 | def createWidgets(self):
|
---|
242 | self.QUIT = Button(self)
|
---|
243 | self.QUIT["text"] = "QUIT"
|
---|
244 | self.QUIT["fg"] = "red"
|
---|
245 | self.QUIT["command"] = self.quit
|
---|
246 |
|
---|
247 | self.QUIT.pack({"side": "left"})
|
---|
248 |
|
---|
249 | self.hi_there = Button(self)
|
---|
250 | self.hi_there["text"] = "Hello",
|
---|
251 | self.hi_there["command"] = self.say_hi
|
---|
252 |
|
---|
253 | self.hi_there.pack({"side": "left"})
|
---|
254 |
|
---|
255 | def __init__(self, master=None):
|
---|
256 | Frame.__init__(self, master)
|
---|
257 | self.pack()
|
---|
258 | self.createWidgets()
|
---|
259 |
|
---|
260 | root = Tk()
|
---|
261 | app = Application(master=root)
|
---|
262 | app.mainloop()
|
---|
263 | root.destroy()
|
---|
264 | \end{verbatim}
|
---|
265 |
|
---|
266 |
|
---|
267 | \subsection{A (Very) Quick Look at Tcl/Tk} % BriefTclTk.html
|
---|
268 |
|
---|
269 | The class hierarchy looks complicated, but in actual practice,
|
---|
270 | application programmers almost always refer to the classes at the very
|
---|
271 | bottom of the hierarchy.
|
---|
272 |
|
---|
273 | Notes:
|
---|
274 | \begin{itemize}
|
---|
275 | \item These classes are provided for the purposes of
|
---|
276 | organizing certain functions under one namespace. They aren't meant to
|
---|
277 | be instantiated independently.
|
---|
278 |
|
---|
279 | \item The \class{Tk} class is meant to be instantiated only once in
|
---|
280 | an application. Application programmers need not instantiate one
|
---|
281 | explicitly, the system creates one whenever any of the other classes
|
---|
282 | are instantiated.
|
---|
283 |
|
---|
284 | \item The \class{Widget} class is not meant to be instantiated, it
|
---|
285 | is meant only for subclassing to make ``real'' widgets (in \Cpp, this
|
---|
286 | is called an `abstract class').
|
---|
287 | \end{itemize}
|
---|
288 |
|
---|
289 | To make use of this reference material, there will be times when you
|
---|
290 | will need to know how to read short passages of Tk and how to identify
|
---|
291 | the various parts of a Tk command.
|
---|
292 | (See section~\ref{tkinter-basic-mapping} for the
|
---|
293 | \refmodule{Tkinter} equivalents of what's below.)
|
---|
294 |
|
---|
295 | Tk scripts are Tcl programs. Like all Tcl programs, Tk scripts are
|
---|
296 | just lists of tokens separated by spaces. A Tk widget is just its
|
---|
297 | \emph{class}, the \emph{options} that help configure it, and the
|
---|
298 | \emph{actions} that make it do useful things.
|
---|
299 |
|
---|
300 | To make a widget in Tk, the command is always of the form:
|
---|
301 |
|
---|
302 | \begin{verbatim}
|
---|
303 | classCommand newPathname options
|
---|
304 | \end{verbatim}
|
---|
305 |
|
---|
306 | \begin{description}
|
---|
307 | \item[\var{classCommand}]
|
---|
308 | denotes which kind of widget to make (a button, a label, a menu...)
|
---|
309 |
|
---|
310 | \item[\var{newPathname}]
|
---|
311 | is the new name for this widget. All names in Tk must be unique. To
|
---|
312 | help enforce this, widgets in Tk are named with \emph{pathnames}, just
|
---|
313 | like files in a file system. The top level widget, the \emph{root},
|
---|
314 | is called \code{.} (period) and children are delimited by more
|
---|
315 | periods. For example, \code{.myApp.controlPanel.okButton} might be
|
---|
316 | the name of a widget.
|
---|
317 |
|
---|
318 | \item[\var{options}]
|
---|
319 | configure the widget's appearance and in some cases, its
|
---|
320 | behavior. The options come in the form of a list of flags and values.
|
---|
321 | Flags are proceeded by a `-', like \UNIX{} shell command flags, and
|
---|
322 | values are put in quotes if they are more than one word.
|
---|
323 | \end{description}
|
---|
324 |
|
---|
325 | For example:
|
---|
326 |
|
---|
327 | \begin{verbatim}
|
---|
328 | button .fred -fg red -text "hi there"
|
---|
329 | ^ ^ \_____________________/
|
---|
330 | | | |
|
---|
331 | class new options
|
---|
332 | command widget (-opt val -opt val ...)
|
---|
333 | \end{verbatim}
|
---|
334 |
|
---|
335 | Once created, the pathname to the widget becomes a new command. This
|
---|
336 | new \var{widget command} is the programmer's handle for getting the new
|
---|
337 | widget to perform some \var{action}. In C, you'd express this as
|
---|
338 | someAction(fred, someOptions), in \Cpp, you would express this as
|
---|
339 | fred.someAction(someOptions), and in Tk, you say:
|
---|
340 |
|
---|
341 | \begin{verbatim}
|
---|
342 | .fred someAction someOptions
|
---|
343 | \end{verbatim}
|
---|
344 |
|
---|
345 | Note that the object name, \code{.fred}, starts with a dot.
|
---|
346 |
|
---|
347 | As you'd expect, the legal values for \var{someAction} will depend on
|
---|
348 | the widget's class: \code{.fred disable} works if fred is a
|
---|
349 | button (fred gets greyed out), but does not work if fred is a label
|
---|
350 | (disabling of labels is not supported in Tk).
|
---|
351 |
|
---|
352 | The legal values of \var{someOptions} is action dependent. Some
|
---|
353 | actions, like \code{disable}, require no arguments, others, like
|
---|
354 | a text-entry box's \code{delete} command, would need arguments
|
---|
355 | to specify what range of text to delete.
|
---|
356 |
|
---|
357 |
|
---|
358 | \subsection{Mapping Basic Tk into Tkinter
|
---|
359 | \label{tkinter-basic-mapping}}
|
---|
360 |
|
---|
361 | Class commands in Tk correspond to class constructors in Tkinter.
|
---|
362 |
|
---|
363 | \begin{verbatim}
|
---|
364 | button .fred =====> fred = Button()
|
---|
365 | \end{verbatim}
|
---|
366 |
|
---|
367 | The master of an object is implicit in the new name given to it at
|
---|
368 | creation time. In Tkinter, masters are specified explicitly.
|
---|
369 |
|
---|
370 | \begin{verbatim}
|
---|
371 | button .panel.fred =====> fred = Button(panel)
|
---|
372 | \end{verbatim}
|
---|
373 |
|
---|
374 | The configuration options in Tk are given in lists of hyphened tags
|
---|
375 | followed by values. In Tkinter, options are specified as
|
---|
376 | keyword-arguments in the instance constructor, and keyword-args for
|
---|
377 | configure calls or as instance indices, in dictionary style, for
|
---|
378 | established instances. See section~\ref{tkinter-setting-options} on
|
---|
379 | setting options.
|
---|
380 |
|
---|
381 | \begin{verbatim}
|
---|
382 | button .fred -fg red =====> fred = Button(panel, fg = "red")
|
---|
383 | .fred configure -fg red =====> fred["fg"] = red
|
---|
384 | OR ==> fred.config(fg = "red")
|
---|
385 | \end{verbatim}
|
---|
386 |
|
---|
387 | In Tk, to perform an action on a widget, use the widget name as a
|
---|
388 | command, and follow it with an action name, possibly with arguments
|
---|
389 | (options). In Tkinter, you call methods on the class instance to
|
---|
390 | invoke actions on the widget. The actions (methods) that a given
|
---|
391 | widget can perform are listed in the Tkinter.py module.
|
---|
392 |
|
---|
393 | \begin{verbatim}
|
---|
394 | .fred invoke =====> fred.invoke()
|
---|
395 | \end{verbatim}
|
---|
396 |
|
---|
397 | To give a widget to the packer (geometry manager), you call pack with
|
---|
398 | optional arguments. In Tkinter, the Pack class holds all this
|
---|
399 | functionality, and the various forms of the pack command are
|
---|
400 | implemented as methods. All widgets in \refmodule{Tkinter} are
|
---|
401 | subclassed from the Packer, and so inherit all the packing
|
---|
402 | methods. See the \refmodule{Tix} module documentation for additional
|
---|
403 | information on the Form geometry manager.
|
---|
404 |
|
---|
405 | \begin{verbatim}
|
---|
406 | pack .fred -side left =====> fred.pack(side = "left")
|
---|
407 | \end{verbatim}
|
---|
408 |
|
---|
409 |
|
---|
410 | \subsection{How Tk and Tkinter are Related} % Relationship.html
|
---|
411 |
|
---|
412 | \note{This was derived from a graphical image; the image will be used
|
---|
413 | more directly in a subsequent version of this document.}
|
---|
414 |
|
---|
415 | From the top down:
|
---|
416 | \begin{description}
|
---|
417 | \item[\b{Your App Here (Python)}]
|
---|
418 | A Python application makes a \refmodule{Tkinter} call.
|
---|
419 |
|
---|
420 | \item[\b{Tkinter (Python Module)}]
|
---|
421 | This call (say, for example, creating a button widget), is
|
---|
422 | implemented in the \emph{Tkinter} module, which is written in
|
---|
423 | Python. This Python function will parse the commands and the
|
---|
424 | arguments and convert them into a form that makes them look as if they
|
---|
425 | had come from a Tk script instead of a Python script.
|
---|
426 |
|
---|
427 | \item[\b{tkinter (C)}]
|
---|
428 | These commands and their arguments will be passed to a C function
|
---|
429 | in the \emph{tkinter} - note the lowercase - extension module.
|
---|
430 |
|
---|
431 | \item[\b{Tk Widgets} (C and Tcl)]
|
---|
432 | This C function is able to make calls into other C modules,
|
---|
433 | including the C functions that make up the Tk library. Tk is
|
---|
434 | implemented in C and some Tcl. The Tcl part of the Tk widgets is used
|
---|
435 | to bind certain default behaviors to widgets, and is executed once at
|
---|
436 | the point where the Python \refmodule{Tkinter} module is
|
---|
437 | imported. (The user never sees this stage).
|
---|
438 |
|
---|
439 | \item[\b{Tk (C)}]
|
---|
440 | The Tk part of the Tk Widgets implement the final mapping to ...
|
---|
441 |
|
---|
442 | \item[\b{Xlib (C)}]
|
---|
443 | the Xlib library to draw graphics on the screen.
|
---|
444 | \end{description}
|
---|
445 |
|
---|
446 |
|
---|
447 | \subsection{Handy Reference}
|
---|
448 |
|
---|
449 | \subsubsection{Setting Options
|
---|
450 | \label{tkinter-setting-options}}
|
---|
451 |
|
---|
452 | Options control things like the color and border width of a widget.
|
---|
453 | Options can be set in three ways:
|
---|
454 |
|
---|
455 | \begin{description}
|
---|
456 | \item[At object creation time, using keyword arguments]:
|
---|
457 | \begin{verbatim}
|
---|
458 | fred = Button(self, fg = "red", bg = "blue")
|
---|
459 | \end{verbatim}
|
---|
460 | \item[After object creation, treating the option name like a dictionary index]:
|
---|
461 | \begin{verbatim}
|
---|
462 | fred["fg"] = "red"
|
---|
463 | fred["bg"] = "blue"
|
---|
464 | \end{verbatim}
|
---|
465 | \item[Use the config() method to update multiple attrs subsequent to
|
---|
466 | object creation]:
|
---|
467 | \begin{verbatim}
|
---|
468 | fred.config(fg = "red", bg = "blue")
|
---|
469 | \end{verbatim}
|
---|
470 | \end{description}
|
---|
471 |
|
---|
472 | For a complete explanation of a given option and its behavior, see the
|
---|
473 | Tk man pages for the widget in question.
|
---|
474 |
|
---|
475 | Note that the man pages list "STANDARD OPTIONS" and "WIDGET SPECIFIC
|
---|
476 | OPTIONS" for each widget. The former is a list of options that are
|
---|
477 | common to many widgets, the latter are the options that are
|
---|
478 | idiosyncratic to that particular widget. The Standard Options are
|
---|
479 | documented on the \manpage{options}{3} man page.
|
---|
480 |
|
---|
481 | No distinction between standard and widget-specific options is made in
|
---|
482 | this document. Some options don't apply to some kinds of widgets.
|
---|
483 | Whether a given widget responds to a particular option depends on the
|
---|
484 | class of the widget; buttons have a \code{command} option, labels do not.
|
---|
485 |
|
---|
486 | The options supported by a given widget are listed in that widget's
|
---|
487 | man page, or can be queried at runtime by calling the
|
---|
488 | \method{config()} method without arguments, or by calling the
|
---|
489 | \method{keys()} method on that widget. The return value of these
|
---|
490 | calls is a dictionary whose key is the name of the option as a string
|
---|
491 | (for example, \code{'relief'}) and whose values are 5-tuples.
|
---|
492 |
|
---|
493 | Some options, like \code{bg} are synonyms for common options with long
|
---|
494 | names (\code{bg} is shorthand for "background"). Passing the
|
---|
495 | \code{config()} method the name of a shorthand option will return a
|
---|
496 | 2-tuple, not 5-tuple. The 2-tuple passed back will contain the name of
|
---|
497 | the synonym and the ``real'' option (such as \code{('bg',
|
---|
498 | 'background')}).
|
---|
499 |
|
---|
500 | \begin{tableiii}{c|l|l}{textrm}{Index}{Meaning}{Example}
|
---|
501 | \lineiii{0}{option name} {\code{'relief'}}
|
---|
502 | \lineiii{1}{option name for database lookup} {\code{'relief'}}
|
---|
503 | \lineiii{2}{option class for database lookup} {\code{'Relief'}}
|
---|
504 | \lineiii{3}{default value} {\code{'raised'}}
|
---|
505 | \lineiii{4}{current value} {\code{'groove'}}
|
---|
506 | \end{tableiii}
|
---|
507 |
|
---|
508 |
|
---|
509 | Example:
|
---|
510 |
|
---|
511 | \begin{verbatim}
|
---|
512 | >>> print fred.config()
|
---|
513 | {'relief' : ('relief', 'relief', 'Relief', 'raised', 'groove')}
|
---|
514 | \end{verbatim}
|
---|
515 |
|
---|
516 | Of course, the dictionary printed will include all the options
|
---|
517 | available and their values. This is meant only as an example.
|
---|
518 |
|
---|
519 |
|
---|
520 | \subsubsection{The Packer} % Packer.html
|
---|
521 | \index{packing (widgets)}
|
---|
522 |
|
---|
523 | The packer is one of Tk's geometry-management mechanisms.
|
---|
524 | % See also \citetitle[classes/ClassPacker.html]{the Packer class interface}.
|
---|
525 |
|
---|
526 | Geometry managers are used to specify the relative positioning of the
|
---|
527 | positioning of widgets within their container - their mutual
|
---|
528 | \emph{master}. In contrast to the more cumbersome \emph{placer}
|
---|
529 | (which is used less commonly, and we do not cover here), the packer
|
---|
530 | takes qualitative relationship specification - \emph{above}, \emph{to
|
---|
531 | the left of}, \emph{filling}, etc - and works everything out to
|
---|
532 | determine the exact placement coordinates for you.
|
---|
533 |
|
---|
534 | The size of any \emph{master} widget is determined by the size of
|
---|
535 | the "slave widgets" inside. The packer is used to control where slave
|
---|
536 | widgets appear inside the master into which they are packed. You can
|
---|
537 | pack widgets into frames, and frames into other frames, in order to
|
---|
538 | achieve the kind of layout you desire. Additionally, the arrangement
|
---|
539 | is dynamically adjusted to accommodate incremental changes to the
|
---|
540 | configuration, once it is packed.
|
---|
541 |
|
---|
542 | Note that widgets do not appear until they have had their geometry
|
---|
543 | specified with a geometry manager. It's a common early mistake to
|
---|
544 | leave out the geometry specification, and then be surprised when the
|
---|
545 | widget is created but nothing appears. A widget will appear only
|
---|
546 | after it has had, for example, the packer's \method{pack()} method
|
---|
547 | applied to it.
|
---|
548 |
|
---|
549 | The pack() method can be called with keyword-option/value pairs that
|
---|
550 | control where the widget is to appear within its container, and how it
|
---|
551 | is to behave when the main application window is resized. Here are
|
---|
552 | some examples:
|
---|
553 |
|
---|
554 | \begin{verbatim}
|
---|
555 | fred.pack() # defaults to side = "top"
|
---|
556 | fred.pack(side = "left")
|
---|
557 | fred.pack(expand = 1)
|
---|
558 | \end{verbatim}
|
---|
559 |
|
---|
560 |
|
---|
561 | \subsubsection{Packer Options}
|
---|
562 |
|
---|
563 | For more extensive information on the packer and the options that it
|
---|
564 | can take, see the man pages and page 183 of John Ousterhout's book.
|
---|
565 |
|
---|
566 | \begin{description}
|
---|
567 | \item[\b{anchor }]
|
---|
568 | Anchor type. Denotes where the packer is to place each slave in its
|
---|
569 | parcel.
|
---|
570 |
|
---|
571 | \item[\b{expand}]
|
---|
572 | Boolean, \code{0} or \code{1}.
|
---|
573 |
|
---|
574 | \item[\b{fill}]
|
---|
575 | Legal values: \code{'x'}, \code{'y'}, \code{'both'}, \code{'none'}.
|
---|
576 |
|
---|
577 | \item[\b{ipadx} and \b{ipady}]
|
---|
578 | A distance - designating internal padding on each side of the slave
|
---|
579 | widget.
|
---|
580 |
|
---|
581 | \item[\b{padx} and \b{pady}]
|
---|
582 | A distance - designating external padding on each side of the slave
|
---|
583 | widget.
|
---|
584 |
|
---|
585 | \item[\b{side}]
|
---|
586 | Legal values are: \code{'left'}, \code{'right'}, \code{'top'},
|
---|
587 | \code{'bottom'}.
|
---|
588 | \end{description}
|
---|
589 |
|
---|
590 |
|
---|
591 | \subsubsection{Coupling Widget Variables} % VarCouplings.html
|
---|
592 |
|
---|
593 | The current-value setting of some widgets (like text entry widgets)
|
---|
594 | can be connected directly to application variables by using special
|
---|
595 | options. These options are \code{variable}, \code{textvariable},
|
---|
596 | \code{onvalue}, \code{offvalue}, and \code{value}. This
|
---|
597 | connection works both ways: if the variable changes for any reason,
|
---|
598 | the widget it's connected to will be updated to reflect the new value.
|
---|
599 |
|
---|
600 | Unfortunately, in the current implementation of \refmodule{Tkinter} it is
|
---|
601 | not possible to hand over an arbitrary Python variable to a widget
|
---|
602 | through a \code{variable} or \code{textvariable} option. The only
|
---|
603 | kinds of variables for which this works are variables that are
|
---|
604 | subclassed from a class called Variable, defined in the
|
---|
605 | \refmodule{Tkinter} module.
|
---|
606 |
|
---|
607 | There are many useful subclasses of Variable already defined:
|
---|
608 | \class{StringVar}, \class{IntVar}, \class{DoubleVar}, and
|
---|
609 | \class{BooleanVar}. To read the current value of such a variable,
|
---|
610 | call the \method{get()} method on
|
---|
611 | it, and to change its value you call the \method{set()} method. If
|
---|
612 | you follow this protocol, the widget will always track the value of
|
---|
613 | the variable, with no further intervention on your part.
|
---|
614 |
|
---|
615 | For example:
|
---|
616 | \begin{verbatim}
|
---|
617 | class App(Frame):
|
---|
618 | def __init__(self, master=None):
|
---|
619 | Frame.__init__(self, master)
|
---|
620 | self.pack()
|
---|
621 |
|
---|
622 | self.entrythingy = Entry()
|
---|
623 | self.entrythingy.pack()
|
---|
624 |
|
---|
625 | # here is the application variable
|
---|
626 | self.contents = StringVar()
|
---|
627 | # set it to some value
|
---|
628 | self.contents.set("this is a variable")
|
---|
629 | # tell the entry widget to watch this variable
|
---|
630 | self.entrythingy["textvariable"] = self.contents
|
---|
631 |
|
---|
632 | # and here we get a callback when the user hits return.
|
---|
633 | # we will have the program print out the value of the
|
---|
634 | # application variable when the user hits return
|
---|
635 | self.entrythingy.bind('<Key-Return>',
|
---|
636 | self.print_contents)
|
---|
637 |
|
---|
638 | def print_contents(self, event):
|
---|
639 | print "hi. contents of entry is now ---->", \
|
---|
640 | self.contents.get()
|
---|
641 | \end{verbatim}
|
---|
642 |
|
---|
643 |
|
---|
644 | \subsubsection{The Window Manager} % WindowMgr.html
|
---|
645 | \index{window manager (widgets)}
|
---|
646 |
|
---|
647 | In Tk, there is a utility command, \code{wm}, for interacting with the
|
---|
648 | window manager. Options to the \code{wm} command allow you to control
|
---|
649 | things like titles, placement, icon bitmaps, and the like. In
|
---|
650 | \refmodule{Tkinter}, these commands have been implemented as methods
|
---|
651 | on the \class{Wm} class. Toplevel widgets are subclassed from the
|
---|
652 | \class{Wm} class, and so can call the \class{Wm} methods directly.
|
---|
653 |
|
---|
654 | %See also \citetitle[classes/ClassWm.html]{the Wm class interface}.
|
---|
655 |
|
---|
656 | To get at the toplevel window that contains a given widget, you can
|
---|
657 | often just refer to the widget's master. Of course if the widget has
|
---|
658 | been packed inside of a frame, the master won't represent a toplevel
|
---|
659 | window. To get at the toplevel window that contains an arbitrary
|
---|
660 | widget, you can call the \method{_root()} method. This
|
---|
661 | method begins with an underscore to denote the fact that this function
|
---|
662 | is part of the implementation, and not an interface to Tk functionality.
|
---|
663 |
|
---|
664 | Here are some examples of typical usage:
|
---|
665 |
|
---|
666 | \begin{verbatim}
|
---|
667 | from Tkinter import *
|
---|
668 | class App(Frame):
|
---|
669 | def __init__(self, master=None):
|
---|
670 | Frame.__init__(self, master)
|
---|
671 | self.pack()
|
---|
672 |
|
---|
673 |
|
---|
674 | # create the application
|
---|
675 | myapp = App()
|
---|
676 |
|
---|
677 | #
|
---|
678 | # here are method calls to the window manager class
|
---|
679 | #
|
---|
680 | myapp.master.title("My Do-Nothing Application")
|
---|
681 | myapp.master.maxsize(1000, 400)
|
---|
682 |
|
---|
683 | # start the program
|
---|
684 | myapp.mainloop()
|
---|
685 | \end{verbatim}
|
---|
686 |
|
---|
687 |
|
---|
688 | \subsubsection{Tk Option Data Types} % OptionTypes.html
|
---|
689 |
|
---|
690 | \index{Tk Option Data Types}
|
---|
691 |
|
---|
692 | \begin{description}
|
---|
693 | \item[anchor]
|
---|
694 | Legal values are points of the compass: \code{"n"},
|
---|
695 | \code{"ne"}, \code{"e"}, \code{"se"}, \code{"s"},
|
---|
696 | \code{"sw"}, \code{"w"}, \code{"nw"}, and also
|
---|
697 | \code{"center"}.
|
---|
698 |
|
---|
699 | \item[bitmap]
|
---|
700 | There are eight built-in, named bitmaps: \code{'error'}, \code{'gray25'},
|
---|
701 | \code{'gray50'}, \code{'hourglass'}, \code{'info'}, \code{'questhead'},
|
---|
702 | \code{'question'}, \code{'warning'}. To specify an X bitmap
|
---|
703 | filename, give the full path to the file, preceded with an \code{@},
|
---|
704 | as in \code{"@/usr/contrib/bitmap/gumby.bit"}.
|
---|
705 |
|
---|
706 | \item[boolean]
|
---|
707 | You can pass integers 0 or 1 or the strings \code{"yes"} or \code{"no"} .
|
---|
708 |
|
---|
709 | \item[callback]
|
---|
710 | This is any Python function that takes no arguments. For example:
|
---|
711 | \begin{verbatim}
|
---|
712 | def print_it():
|
---|
713 | print "hi there"
|
---|
714 | fred["command"] = print_it
|
---|
715 | \end{verbatim}
|
---|
716 |
|
---|
717 | \item[color]
|
---|
718 | Colors can be given as the names of X colors in the rgb.txt file,
|
---|
719 | or as strings representing RGB values in 4 bit: \code{"\#RGB"}, 8
|
---|
720 | bit: \code{"\#RRGGBB"}, 12 bit" \code{"\#RRRGGGBBB"}, or 16 bit
|
---|
721 | \code{"\#RRRRGGGGBBBB"} ranges, where R,G,B here represent any
|
---|
722 | legal hex digit. See page 160 of Ousterhout's book for details.
|
---|
723 |
|
---|
724 | \item[cursor]
|
---|
725 | The standard X cursor names from \file{cursorfont.h} can be used,
|
---|
726 | without the \code{XC_} prefix. For example to get a hand cursor
|
---|
727 | (\constant{XC_hand2}), use the string \code{"hand2"}. You can also
|
---|
728 | specify a bitmap and mask file of your own. See page 179 of
|
---|
729 | Ousterhout's book.
|
---|
730 |
|
---|
731 | \item[distance]
|
---|
732 | Screen distances can be specified in either pixels or absolute
|
---|
733 | distances. Pixels are given as numbers and absolute distances as
|
---|
734 | strings, with the trailing character denoting units: \code{c}
|
---|
735 | for centimetres, \code{i} for inches, \code{m} for millimetres,
|
---|
736 | \code{p} for printer's points. For example, 3.5 inches is expressed
|
---|
737 | as \code{"3.5i"}.
|
---|
738 |
|
---|
739 | \item[font]
|
---|
740 | Tk uses a list font name format, such as \code{\{courier 10 bold\}}.
|
---|
741 | Font sizes with positive numbers are measured in points;
|
---|
742 | sizes with negative numbers are measured in pixels.
|
---|
743 |
|
---|
744 | \item[geometry]
|
---|
745 | This is a string of the form \samp{\var{width}x\var{height}}, where
|
---|
746 | width and height are measured in pixels for most widgets (in
|
---|
747 | characters for widgets displaying text). For example:
|
---|
748 | \code{fred["geometry"] = "200x100"}.
|
---|
749 |
|
---|
750 | \item[justify]
|
---|
751 | Legal values are the strings: \code{"left"},
|
---|
752 | \code{"center"}, \code{"right"}, and \code{"fill"}.
|
---|
753 |
|
---|
754 | \item[region]
|
---|
755 | This is a string with four space-delimited elements, each of
|
---|
756 | which is a legal distance (see above). For example: \code{"2 3 4
|
---|
757 | 5"} and \code{"3i 2i 4.5i 2i"} and \code{"3c 2c 4c 10.43c"}
|
---|
758 | are all legal regions.
|
---|
759 |
|
---|
760 | \item[relief]
|
---|
761 | Determines what the border style of a widget will be. Legal
|
---|
762 | values are: \code{"raised"}, \code{"sunken"},
|
---|
763 | \code{"flat"}, \code{"groove"}, and \code{"ridge"}.
|
---|
764 |
|
---|
765 | \item[scrollcommand]
|
---|
766 | This is almost always the \method{set()} method of some scrollbar
|
---|
767 | widget, but can be any widget method that takes a single argument.
|
---|
768 | Refer to the file \file{Demo/tkinter/matt/canvas-with-scrollbars.py}
|
---|
769 | in the Python source distribution for an example.
|
---|
770 |
|
---|
771 | \item[wrap:]
|
---|
772 | Must be one of: \code{"none"}, \code{"char"}, or \code{"word"}.
|
---|
773 | \end{description}
|
---|
774 |
|
---|
775 |
|
---|
776 | \subsubsection{Bindings and Events} % Bindings.html
|
---|
777 |
|
---|
778 | \index{bind (widgets)}
|
---|
779 | \index{events (widgets)}
|
---|
780 |
|
---|
781 | The bind method from the widget command allows you to watch for
|
---|
782 | certain events and to have a callback function trigger when that event
|
---|
783 | type occurs. The form of the bind method is:
|
---|
784 |
|
---|
785 | \begin{verbatim}
|
---|
786 | def bind(self, sequence, func, add=''):
|
---|
787 | \end{verbatim}
|
---|
788 | where:
|
---|
789 |
|
---|
790 | \begin{description}
|
---|
791 | \item[sequence]
|
---|
792 | is a string that denotes the target kind of event. (See the bind
|
---|
793 | man page and page 201 of John Ousterhout's book for details).
|
---|
794 |
|
---|
795 | \item[func]
|
---|
796 | is a Python function, taking one argument, to be invoked when the
|
---|
797 | event occurs. An Event instance will be passed as the argument.
|
---|
798 | (Functions deployed this way are commonly known as \var{callbacks}.)
|
---|
799 |
|
---|
800 | \item[add]
|
---|
801 | is optional, either \samp{} or \samp{+}. Passing an empty string
|
---|
802 | denotes that this binding is to replace any other bindings that this
|
---|
803 | event is associated with. Preceeding with a \samp{+} means that this
|
---|
804 | function is to be added to the list of functions bound to this event type.
|
---|
805 | \end{description}
|
---|
806 |
|
---|
807 | For example:
|
---|
808 | \begin{verbatim}
|
---|
809 | def turnRed(self, event):
|
---|
810 | event.widget["activeforeground"] = "red"
|
---|
811 |
|
---|
812 | self.button.bind("<Enter>", self.turnRed)
|
---|
813 | \end{verbatim}
|
---|
814 |
|
---|
815 | Notice how the widget field of the event is being accessed in the
|
---|
816 | \method{turnRed()} callback. This field contains the widget that
|
---|
817 | caught the X event. The following table lists the other event fields
|
---|
818 | you can access, and how they are denoted in Tk, which can be useful
|
---|
819 | when referring to the Tk man pages.
|
---|
820 |
|
---|
821 | \begin{verbatim}
|
---|
822 | Tk Tkinter Event Field Tk Tkinter Event Field
|
---|
823 | -- ------------------- -- -------------------
|
---|
824 | %f focus %A char
|
---|
825 | %h height %E send_event
|
---|
826 | %k keycode %K keysym
|
---|
827 | %s state %N keysym_num
|
---|
828 | %t time %T type
|
---|
829 | %w width %W widget
|
---|
830 | %x x %X x_root
|
---|
831 | %y y %Y y_root
|
---|
832 | \end{verbatim}
|
---|
833 |
|
---|
834 |
|
---|
835 | \subsubsection{The index Parameter} % Index.html
|
---|
836 |
|
---|
837 | A number of widgets require``index'' parameters to be passed. These
|
---|
838 | are used to point at a specific place in a Text widget, or to
|
---|
839 | particular characters in an Entry widget, or to particular menu items
|
---|
840 | in a Menu widget.
|
---|
841 |
|
---|
842 | \begin{description}
|
---|
843 | \item[\b{Entry widget indexes (index, view index, etc.)}]
|
---|
844 | Entry widgets have options that refer to character positions in the
|
---|
845 | text being displayed. You can use these \refmodule{Tkinter} functions
|
---|
846 | to access these special points in text widgets:
|
---|
847 |
|
---|
848 | \begin{description}
|
---|
849 | \item[AtEnd()]
|
---|
850 | refers to the last position in the text
|
---|
851 |
|
---|
852 | \item[AtInsert()]
|
---|
853 | refers to the point where the text cursor is
|
---|
854 |
|
---|
855 | \item[AtSelFirst()]
|
---|
856 | indicates the beginning point of the selected text
|
---|
857 |
|
---|
858 | \item[AtSelLast()]
|
---|
859 | denotes the last point of the selected text and finally
|
---|
860 |
|
---|
861 | \item[At(x\optional{, y})]
|
---|
862 | refers to the character at pixel location \var{x}, \var{y} (with
|
---|
863 | \var{y} not used in the case of a text entry widget, which contains a
|
---|
864 | single line of text).
|
---|
865 | \end{description}
|
---|
866 |
|
---|
867 | \item[\b{Text widget indexes}]
|
---|
868 | The index notation for Text widgets is very rich and is best described
|
---|
869 | in the Tk man pages.
|
---|
870 |
|
---|
871 | \item[\b{Menu indexes (menu.invoke(), menu.entryconfig(), etc.)}]
|
---|
872 |
|
---|
873 | Some options and methods for menus manipulate specific menu entries.
|
---|
874 | Anytime a menu index is needed for an option or a parameter, you may
|
---|
875 | pass in:
|
---|
876 | \begin{itemize}
|
---|
877 | \item an integer which refers to the numeric position of the entry in
|
---|
878 | the widget, counted from the top, starting with 0;
|
---|
879 | \item the string \code{'active'}, which refers to the menu position that is
|
---|
880 | currently under the cursor;
|
---|
881 | \item the string \code{"last"} which refers to the last menu
|
---|
882 | item;
|
---|
883 | \item An integer preceded by \code{@}, as in \code{@6}, where the integer is
|
---|
884 | interpreted as a y pixel coordinate in the menu's coordinate system;
|
---|
885 | \item the string \code{"none"}, which indicates no menu entry at all, most
|
---|
886 | often used with menu.activate() to deactivate all entries, and
|
---|
887 | finally,
|
---|
888 | \item a text string that is pattern matched against the label of the
|
---|
889 | menu entry, as scanned from the top of the menu to the bottom. Note
|
---|
890 | that this index type is considered after all the others, which means
|
---|
891 | that matches for menu items labelled \code{last}, \code{active}, or
|
---|
892 | \code{none} may be interpreted as the above literals, instead.
|
---|
893 | \end{itemize}
|
---|
894 | \end{description}
|
---|
895 |
|
---|
896 | \subsubsection{Images}
|
---|
897 |
|
---|
898 | Bitmap/Pixelmap images can be created through the subclasses of
|
---|
899 | \class{Tkinter.Image}:
|
---|
900 |
|
---|
901 | \begin{itemize}
|
---|
902 | \item \class{BitmapImage} can be used for X11 bitmap data.
|
---|
903 | \item \class{PhotoImage} can be used for GIF and PPM/PGM color bitmaps.
|
---|
904 | \end{itemize}
|
---|
905 |
|
---|
906 | Either type of image is created through either the \code{file} or the
|
---|
907 | \code{data} option (other options are available as well).
|
---|
908 |
|
---|
909 | The image object can then be used wherever an \code{image} option is
|
---|
910 | supported by some widget (e.g. labels, buttons, menus). In these
|
---|
911 | cases, Tk will not keep a reference to the image. When the last Python
|
---|
912 | reference to the image object is deleted, the image data is deleted as
|
---|
913 | well, and Tk will display an empty box wherever the image was used.
|
---|
914 |
|
---|
915 | \section{\module{Tix} ---
|
---|
916 | Extension widgets for Tk}
|
---|
917 |
|
---|
918 | \declaremodule{standard}{Tix}
|
---|
919 | \modulesynopsis{Tk Extension Widgets for Tkinter}
|
---|
920 | \sectionauthor{Mike Clarkson}{mikeclarkson@users.sourceforge.net}
|
---|
921 |
|
---|
922 | \index{Tix}
|
---|
923 |
|
---|
924 | The \module{Tix} (Tk Interface Extension) module provides an
|
---|
925 | additional rich set of widgets. Although the standard Tk library has
|
---|
926 | many useful widgets, they are far from complete. The \module{Tix}
|
---|
927 | library provides most of the commonly needed widgets that are missing
|
---|
928 | from standard Tk: \class{HList}, \class{ComboBox}, \class{Control}
|
---|
929 | (a.k.a. SpinBox) and an assortment of scrollable widgets. \module{Tix}
|
---|
930 | also includes many more widgets that are generally useful in a wide
|
---|
931 | range of applications: \class{NoteBook}, \class{FileEntry},
|
---|
932 | \class{PanedWindow}, etc; there are more than 40 of them.
|
---|
933 |
|
---|
934 | With all these new widgets, you can introduce new interaction
|
---|
935 | techniques into applications, creating more useful and more intuitive
|
---|
936 | user interfaces. You can design your application by choosing the most
|
---|
937 | appropriate widgets to match the special needs of your application and
|
---|
938 | users.
|
---|
939 |
|
---|
940 | \begin{seealso}
|
---|
941 | \seetitle[http://tix.sourceforge.net/]
|
---|
942 | {Tix Homepage}
|
---|
943 | {The home page for \module{Tix}. This includes links to
|
---|
944 | additional documentation and downloads.}
|
---|
945 | \seetitle[http://tix.sourceforge.net/dist/current/man/]
|
---|
946 | {Tix Man Pages}
|
---|
947 | {On-line version of the man pages and reference material.}
|
---|
948 | \seetitle[http://tix.sourceforge.net/dist/current/docs/tix-book/tix.book.html]
|
---|
949 | {Tix Programming Guide}
|
---|
950 | {On-line version of the programmer's reference material.}
|
---|
951 | \seetitle[http://tix.sourceforge.net/Tide/]
|
---|
952 | {Tix Development Applications}
|
---|
953 | {Tix applications for development of Tix and Tkinter programs.
|
---|
954 | Tide applications work under Tk or Tkinter, and include
|
---|
955 | \program{TixInspect}, an inspector to remotely modify and
|
---|
956 | debug Tix/Tk/Tkinter applications.}
|
---|
957 | \end{seealso}
|
---|
958 |
|
---|
959 |
|
---|
960 | \subsection{Using Tix}
|
---|
961 |
|
---|
962 | \begin{classdesc}{Tix}{screenName\optional{, baseName\optional{, className}}}
|
---|
963 | Toplevel widget of Tix which represents mostly the main window
|
---|
964 | of an application. It has an associated Tcl interpreter.
|
---|
965 |
|
---|
966 | Classes in the \refmodule{Tix} module subclasses the classes in the
|
---|
967 | \refmodule{Tkinter} module. The former imports the latter, so to use
|
---|
968 | \refmodule{Tix} with Tkinter, all you need to do is to import one
|
---|
969 | module. In general, you can just import \refmodule{Tix}, and replace
|
---|
970 | the toplevel call to \class{Tkinter.Tk} with \class{Tix.Tk}:
|
---|
971 | \begin{verbatim}
|
---|
972 | import Tix
|
---|
973 | from Tkconstants import *
|
---|
974 | root = Tix.Tk()
|
---|
975 | \end{verbatim}
|
---|
976 | \end{classdesc}
|
---|
977 |
|
---|
978 | To use \refmodule{Tix}, you must have the \refmodule{Tix} widgets installed,
|
---|
979 | usually alongside your installation of the Tk widgets.
|
---|
980 | To test your installation, try the following:
|
---|
981 | \begin{verbatim}
|
---|
982 | import Tix
|
---|
983 | root = Tix.Tk()
|
---|
984 | root.tk.eval('package require Tix')
|
---|
985 | \end{verbatim}
|
---|
986 |
|
---|
987 | If this fails, you have a Tk installation problem which must be
|
---|
988 | resolved before proceeding. Use the environment variable \envvar{TIX_LIBRARY}
|
---|
989 | to point to the installed \refmodule{Tix} library directory, and
|
---|
990 | make sure you have the dynamic object library (\file{tix8183.dll} or
|
---|
991 | \file{libtix8183.so}) in the same directory that contains your Tk
|
---|
992 | dynamic object library (\file{tk8183.dll} or \file{libtk8183.so}). The
|
---|
993 | directory with the dynamic object library should also have a file
|
---|
994 | called \file{pkgIndex.tcl} (case sensitive), which contains the line:
|
---|
995 |
|
---|
996 | \begin{verbatim}
|
---|
997 | package ifneeded Tix 8.1 [list load "[file join $dir tix8183.dll]" Tix]
|
---|
998 | \end{verbatim} % $ <-- bow to font-lock
|
---|
999 |
|
---|
1000 |
|
---|
1001 | \subsection{Tix Widgets}
|
---|
1002 |
|
---|
1003 | \ulink{Tix}
|
---|
1004 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/TixIntro.htm}
|
---|
1005 | introduces over 40 widget classes to the \refmodule{Tkinter}
|
---|
1006 | repertoire. There is a demo of all the \refmodule{Tix} widgets in the
|
---|
1007 | \file{Demo/tix} directory of the standard distribution.
|
---|
1008 |
|
---|
1009 |
|
---|
1010 | % The Python sample code is still being added to Python, hence commented out
|
---|
1011 |
|
---|
1012 |
|
---|
1013 | \subsubsection{Basic Widgets}
|
---|
1014 |
|
---|
1015 | \begin{classdesc}{Balloon}{}
|
---|
1016 | A \ulink{Balloon}
|
---|
1017 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixBalloon.htm}
|
---|
1018 | that pops up over a widget to provide help. When the user moves the
|
---|
1019 | cursor inside a widget to which a Balloon widget has been bound, a
|
---|
1020 | small pop-up window with a descriptive message will be shown on the
|
---|
1021 | screen.
|
---|
1022 | \end{classdesc}
|
---|
1023 |
|
---|
1024 | % Python Demo of:
|
---|
1025 | % \ulink{Balloon}{http://tix.sourceforge.net/dist/current/demos/samples/Balloon.tcl}
|
---|
1026 |
|
---|
1027 | \begin{classdesc}{ButtonBox}{}
|
---|
1028 | The \ulink{ButtonBox}
|
---|
1029 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixButtonBox.htm}
|
---|
1030 | widget creates a box of buttons, such as is commonly used for \code{Ok
|
---|
1031 | Cancel}.
|
---|
1032 | \end{classdesc}
|
---|
1033 |
|
---|
1034 | % Python Demo of:
|
---|
1035 | % \ulink{ButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/BtnBox.tcl}
|
---|
1036 |
|
---|
1037 | \begin{classdesc}{ComboBox}{}
|
---|
1038 | The \ulink{ComboBox}
|
---|
1039 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixComboBox.htm}
|
---|
1040 | widget is similar to the combo box control in MS Windows. The user can
|
---|
1041 | select a choice by either typing in the entry subwdget or selecting
|
---|
1042 | from the listbox subwidget.
|
---|
1043 | \end{classdesc}
|
---|
1044 |
|
---|
1045 | % Python Demo of:
|
---|
1046 | % \ulink{ComboBox}{http://tix.sourceforge.net/dist/current/demos/samples/ComboBox.tcl}
|
---|
1047 |
|
---|
1048 | \begin{classdesc}{Control}{}
|
---|
1049 | The \ulink{Control}
|
---|
1050 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixControl.htm}
|
---|
1051 | widget is also known as the \class{SpinBox} widget. The user can
|
---|
1052 | adjust the value by pressing the two arrow buttons or by entering the
|
---|
1053 | value directly into the entry. The new value will be checked against
|
---|
1054 | the user-defined upper and lower limits.
|
---|
1055 | \end{classdesc}
|
---|
1056 |
|
---|
1057 | % Python Demo of:
|
---|
1058 | % \ulink{Control}{http://tix.sourceforge.net/dist/current/demos/samples/Control.tcl}
|
---|
1059 |
|
---|
1060 | \begin{classdesc}{LabelEntry}{}
|
---|
1061 | The \ulink{LabelEntry}
|
---|
1062 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelEntry.htm}
|
---|
1063 | widget packages an entry widget and a label into one mega widget. It
|
---|
1064 | can be used be used to simplify the creation of ``entry-form'' type of
|
---|
1065 | interface.
|
---|
1066 | \end{classdesc}
|
---|
1067 |
|
---|
1068 | % Python Demo of:
|
---|
1069 | % \ulink{LabelEntry}{http://tix.sourceforge.net/dist/current/demos/samples/LabEntry.tcl}
|
---|
1070 |
|
---|
1071 | \begin{classdesc}{LabelFrame}{}
|
---|
1072 | The \ulink{LabelFrame}
|
---|
1073 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelFrame.htm}
|
---|
1074 | widget packages a frame widget and a label into one mega widget. To
|
---|
1075 | create widgets inside a LabelFrame widget, one creates the new widgets
|
---|
1076 | relative to the \member{frame} subwidget and manage them inside the
|
---|
1077 | \member{frame} subwidget.
|
---|
1078 | \end{classdesc}
|
---|
1079 |
|
---|
1080 | % Python Demo of:
|
---|
1081 | % \ulink{LabelFrame}{http://tix.sourceforge.net/dist/current/demos/samples/LabFrame.tcl}
|
---|
1082 |
|
---|
1083 | \begin{classdesc}{Meter}{}
|
---|
1084 | The \ulink{Meter}
|
---|
1085 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixMeter.htm}
|
---|
1086 | widget can be used to show the progress of a background job which may
|
---|
1087 | take a long time to execute.
|
---|
1088 | \end{classdesc}
|
---|
1089 |
|
---|
1090 | % Python Demo of:
|
---|
1091 | % \ulink{Meter}{http://tix.sourceforge.net/dist/current/demos/samples/Meter.tcl}
|
---|
1092 |
|
---|
1093 | \begin{classdesc}{OptionMenu}{}
|
---|
1094 | The \ulink{OptionMenu}
|
---|
1095 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixOptionMenu.htm}
|
---|
1096 | creates a menu button of options.
|
---|
1097 | \end{classdesc}
|
---|
1098 |
|
---|
1099 | % Python Demo of:
|
---|
1100 | % \ulink{OptionMenu}{http://tix.sourceforge.net/dist/current/demos/samples/OptMenu.tcl}
|
---|
1101 |
|
---|
1102 | \begin{classdesc}{PopupMenu}{}
|
---|
1103 | The \ulink{PopupMenu}
|
---|
1104 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPopupMenu.htm}
|
---|
1105 | widget can be used as a replacement of the \code{tk_popup}
|
---|
1106 | command. The advantage of the \refmodule{Tix} \class{PopupMenu} widget
|
---|
1107 | is it requires less application code to manipulate.
|
---|
1108 | \end{classdesc}
|
---|
1109 |
|
---|
1110 | % Python Demo of:
|
---|
1111 | % \ulink{PopupMenu}{http://tix.sourceforge.net/dist/current/demos/samples/PopMenu.tcl}
|
---|
1112 |
|
---|
1113 | \begin{classdesc}{Select}{}
|
---|
1114 | The \ulink{Select}
|
---|
1115 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixSelect.htm}
|
---|
1116 | widget is a container of button subwidgets. It can be used to provide
|
---|
1117 | radio-box or check-box style of selection options for the user.
|
---|
1118 | \end{classdesc}
|
---|
1119 |
|
---|
1120 | % Python Demo of:
|
---|
1121 | % \ulink{Select}{http://tix.sourceforge.net/dist/current/demos/samples/Select.tcl}
|
---|
1122 |
|
---|
1123 | \begin{classdesc}{StdButtonBox}{}
|
---|
1124 | The \ulink{StdButtonBox}
|
---|
1125 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixStdButtonBox.htm}
|
---|
1126 | widget is a group of standard buttons for Motif-like dialog boxes.
|
---|
1127 | \end{classdesc}
|
---|
1128 |
|
---|
1129 | % Python Demo of:
|
---|
1130 | % \ulink{StdButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/StdBBox.tcl}
|
---|
1131 |
|
---|
1132 |
|
---|
1133 | \subsubsection{File Selectors}
|
---|
1134 |
|
---|
1135 | \begin{classdesc}{DirList}{}
|
---|
1136 | The \ulink{DirList}
|
---|
1137 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirList.htm} widget
|
---|
1138 | displays a list view of a directory, its previous directories and its
|
---|
1139 | sub-directories. The user can choose one of the directories displayed
|
---|
1140 | in the list or change to another directory.
|
---|
1141 | \end{classdesc}
|
---|
1142 |
|
---|
1143 | % Python Demo of:
|
---|
1144 | % \ulink{DirList}{http://tix.sourceforge.net/dist/current/demos/samples/DirList.tcl}
|
---|
1145 |
|
---|
1146 | \begin{classdesc}{DirTree}{}
|
---|
1147 | The \ulink{DirTree}
|
---|
1148 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirTree.htm}
|
---|
1149 | widget displays a tree view of a directory, its previous directories
|
---|
1150 | and its sub-directories. The user can choose one of the directories
|
---|
1151 | displayed in the list or change to another directory.
|
---|
1152 | \end{classdesc}
|
---|
1153 |
|
---|
1154 | % Python Demo of:
|
---|
1155 | % \ulink{DirTree}{http://tix.sourceforge.net/dist/current/demos/samples/DirTree.tcl}
|
---|
1156 |
|
---|
1157 | \begin{classdesc}{DirSelectDialog}{}
|
---|
1158 | The \ulink{DirSelectDialog}
|
---|
1159 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirSelectDialog.htm}
|
---|
1160 | widget presents the directories in the file system in a dialog
|
---|
1161 | window. The user can use this dialog window to navigate through the
|
---|
1162 | file system to select the desired directory.
|
---|
1163 | \end{classdesc}
|
---|
1164 |
|
---|
1165 | % Python Demo of:
|
---|
1166 | % \ulink{DirSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/DirDlg.tcl}
|
---|
1167 |
|
---|
1168 | \begin{classdesc}{DirSelectBox}{}
|
---|
1169 | The \class{DirSelectBox} is similar
|
---|
1170 | to the standard Motif(TM) directory-selection box. It is generally used for
|
---|
1171 | the user to choose a directory. DirSelectBox stores the directories mostly
|
---|
1172 | recently selected into a ComboBox widget so that they can be quickly
|
---|
1173 | selected again.
|
---|
1174 | \end{classdesc}
|
---|
1175 |
|
---|
1176 | \begin{classdesc}{ExFileSelectBox}{}
|
---|
1177 | The \ulink{ExFileSelectBox}
|
---|
1178 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixExFileSelectBox.htm}
|
---|
1179 | widget is usually embedded in a tixExFileSelectDialog widget. It
|
---|
1180 | provides an convenient method for the user to select files. The style
|
---|
1181 | of the \class{ExFileSelectBox} widget is very similar to the standard
|
---|
1182 | file dialog on MS Windows 3.1.
|
---|
1183 | \end{classdesc}
|
---|
1184 |
|
---|
1185 | % Python Demo of:
|
---|
1186 | %\ulink{ExFileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/EFileDlg.tcl}
|
---|
1187 |
|
---|
1188 | \begin{classdesc}{FileSelectBox}{}
|
---|
1189 | The \ulink{FileSelectBox}
|
---|
1190 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileSelectBox.htm}
|
---|
1191 | is similar to the standard Motif(TM) file-selection box. It is
|
---|
1192 | generally used for the user to choose a file. FileSelectBox stores the
|
---|
1193 | files mostly recently selected into a \class{ComboBox} widget so that
|
---|
1194 | they can be quickly selected again.
|
---|
1195 | \end{classdesc}
|
---|
1196 |
|
---|
1197 | % Python Demo of:
|
---|
1198 | % \ulink{FileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/FileDlg.tcl}
|
---|
1199 |
|
---|
1200 | \begin{classdesc}{FileEntry}{}
|
---|
1201 | The \ulink{FileEntry}
|
---|
1202 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileEntry.htm}
|
---|
1203 | widget can be used to input a filename. The user can type in the
|
---|
1204 | filename manually. Alternatively, the user can press the button widget
|
---|
1205 | that sits next to the entry, which will bring up a file selection
|
---|
1206 | dialog.
|
---|
1207 | \end{classdesc}
|
---|
1208 |
|
---|
1209 | % Python Demo of:
|
---|
1210 | % \ulink{FileEntry}{http://tix.sourceforge.net/dist/current/demos/samples/FileEnt.tcl}
|
---|
1211 |
|
---|
1212 |
|
---|
1213 | \subsubsection{Hierachical ListBox}
|
---|
1214 |
|
---|
1215 | \begin{classdesc}{HList}{}
|
---|
1216 | The \ulink{HList}
|
---|
1217 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixHList.htm}
|
---|
1218 | widget can be used to display any data that have a hierarchical
|
---|
1219 | structure, for example, file system directory trees. The list entries
|
---|
1220 | are indented and connected by branch lines according to their places
|
---|
1221 | in the hierarchy.
|
---|
1222 | \end{classdesc}
|
---|
1223 |
|
---|
1224 | % Python Demo of:
|
---|
1225 | % \ulink{HList}{http://tix.sourceforge.net/dist/current/demos/samples/HList1.tcl}
|
---|
1226 |
|
---|
1227 | \begin{classdesc}{CheckList}{}
|
---|
1228 | The \ulink{CheckList}
|
---|
1229 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixCheckList.htm}
|
---|
1230 | widget displays a list of items to be selected by the user. CheckList
|
---|
1231 | acts similarly to the Tk checkbutton or radiobutton widgets, except it
|
---|
1232 | is capable of handling many more items than checkbuttons or
|
---|
1233 | radiobuttons.
|
---|
1234 | \end{classdesc}
|
---|
1235 |
|
---|
1236 | % Python Demo of:
|
---|
1237 | % \ulink{ CheckList}{http://tix.sourceforge.net/dist/current/demos/samples/ChkList.tcl}
|
---|
1238 | % Python Demo of:
|
---|
1239 | % \ulink{ScrolledHList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList.tcl}
|
---|
1240 | % Python Demo of:
|
---|
1241 | % \ulink{ScrolledHList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList2.tcl}
|
---|
1242 |
|
---|
1243 | \begin{classdesc}{Tree}{}
|
---|
1244 | The \ulink{Tree}
|
---|
1245 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTree.htm}
|
---|
1246 | widget can be used to display hierarchical data in a tree form. The
|
---|
1247 | user can adjust the view of the tree by opening or closing parts of
|
---|
1248 | the tree.
|
---|
1249 | \end{classdesc}
|
---|
1250 |
|
---|
1251 | % Python Demo of:
|
---|
1252 | % \ulink{Tree}{http://tix.sourceforge.net/dist/current/demos/samples/Tree.tcl}
|
---|
1253 |
|
---|
1254 | % Python Demo of:
|
---|
1255 | % \ulink{Tree (Dynamic)}{http://tix.sourceforge.net/dist/current/demos/samples/DynTree.tcl}
|
---|
1256 |
|
---|
1257 |
|
---|
1258 | \subsubsection{Tabular ListBox}
|
---|
1259 |
|
---|
1260 | \begin{classdesc}{TList}{}
|
---|
1261 | The \ulink{TList}
|
---|
1262 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTList.htm}
|
---|
1263 | widget can be used to display data in a tabular format. The list
|
---|
1264 | entries of a \class{TList} widget are similar to the entries in the Tk
|
---|
1265 | listbox widget. The main differences are (1) the \class{TList} widget
|
---|
1266 | can display the list entries in a two dimensional format and (2) you
|
---|
1267 | can use graphical images as well as multiple colors and fonts for the
|
---|
1268 | list entries.
|
---|
1269 | \end{classdesc}
|
---|
1270 |
|
---|
1271 | % Python Demo of:
|
---|
1272 | % \ulink{ScrolledTList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/STList1.tcl}
|
---|
1273 | % Python Demo of:
|
---|
1274 | % \ulink{ScrolledTList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/STList2.tcl}
|
---|
1275 |
|
---|
1276 | % Grid has yet to be added to Python
|
---|
1277 | % \subsubsection{Grid Widget}
|
---|
1278 | % Python Demo of:
|
---|
1279 | % \ulink{Simple Grid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid0.tcl}
|
---|
1280 | % Python Demo of:
|
---|
1281 | % \ulink{ScrolledGrid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid1.tcl}
|
---|
1282 | % Python Demo of:
|
---|
1283 | % \ulink{Editable Grid}{http://tix.sourceforge.net/dist/current/demos/samples/EditGrid.tcl}
|
---|
1284 |
|
---|
1285 |
|
---|
1286 | \subsubsection{Manager Widgets}
|
---|
1287 |
|
---|
1288 | \begin{classdesc}{PanedWindow}{}
|
---|
1289 | The \ulink{PanedWindow}
|
---|
1290 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPanedWindow.htm}
|
---|
1291 | widget allows the user to interactively manipulate the sizes of
|
---|
1292 | several panes. The panes can be arranged either vertically or
|
---|
1293 | horizontally. The user changes the sizes of the panes by dragging the
|
---|
1294 | resize handle between two panes.
|
---|
1295 | \end{classdesc}
|
---|
1296 |
|
---|
1297 | % Python Demo of:
|
---|
1298 | % \ulink{PanedWindow}{http://tix.sourceforge.net/dist/current/demos/samples/PanedWin.tcl}
|
---|
1299 |
|
---|
1300 | \begin{classdesc}{ListNoteBook}{}
|
---|
1301 | The \ulink{ListNoteBook}
|
---|
1302 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixListNoteBook.htm}
|
---|
1303 | widget is very similar to the \class{TixNoteBook} widget: it can be
|
---|
1304 | used to display many windows in a limited space using a notebook
|
---|
1305 | metaphor. The notebook is divided into a stack of pages (windows). At
|
---|
1306 | one time only one of these pages can be shown. The user can navigate
|
---|
1307 | through these pages by choosing the name of the desired page in the
|
---|
1308 | \member{hlist} subwidget.
|
---|
1309 | \end{classdesc}
|
---|
1310 |
|
---|
1311 | % Python Demo of:
|
---|
1312 | % \ulink{ListNoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/ListNBK.tcl}
|
---|
1313 |
|
---|
1314 | \begin{classdesc}{NoteBook}{}
|
---|
1315 | The \ulink{NoteBook}
|
---|
1316 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixNoteBook.htm}
|
---|
1317 | widget can be used to display many windows in a limited space using a
|
---|
1318 | notebook metaphor. The notebook is divided into a stack of pages. At
|
---|
1319 | one time only one of these pages can be shown. The user can navigate
|
---|
1320 | through these pages by choosing the visual ``tabs'' at the top of the
|
---|
1321 | NoteBook widget.
|
---|
1322 | \end{classdesc}
|
---|
1323 |
|
---|
1324 | % Python Demo of:
|
---|
1325 | % \ulink{NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/NoteBook.tcl}
|
---|
1326 |
|
---|
1327 |
|
---|
1328 | % \subsubsection{Scrolled Widgets}
|
---|
1329 | % Python Demo of:
|
---|
1330 | % \ulink{ScrolledListBox}{http://tix.sourceforge.net/dist/current/demos/samples/SListBox.tcl}
|
---|
1331 | % Python Demo of:
|
---|
1332 | % \ulink{ScrolledText}{http://tix.sourceforge.net/dist/current/demos/samples/SText.tcl}
|
---|
1333 | % Python Demo of:
|
---|
1334 | % \ulink{ScrolledWindow}{http://tix.sourceforge.net/dist/current/demos/samples/SWindow.tcl}
|
---|
1335 | % Python Demo of:
|
---|
1336 | % \ulink{Canvas Object View}{http://tix.sourceforge.net/dist/current/demos/samples/CObjView.tcl}
|
---|
1337 |
|
---|
1338 |
|
---|
1339 | \subsubsection{Image Types}
|
---|
1340 |
|
---|
1341 | The \refmodule{Tix} module adds:
|
---|
1342 | \begin{itemize}
|
---|
1343 | \item
|
---|
1344 | \ulink{pixmap}
|
---|
1345 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/pixmap.htm}
|
---|
1346 | capabilities to all \refmodule{Tix} and \refmodule{Tkinter} widgets to
|
---|
1347 | create color images from XPM files.
|
---|
1348 |
|
---|
1349 | % Python Demo of:
|
---|
1350 | % \ulink{XPM Image In Button}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm.tcl}
|
---|
1351 |
|
---|
1352 | % Python Demo of:
|
---|
1353 | % \ulink{XPM Image In Menu}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm1.tcl}
|
---|
1354 |
|
---|
1355 | \item
|
---|
1356 | \ulink{Compound}
|
---|
1357 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/compound.htm}
|
---|
1358 | image types can be used to create images that consists of multiple
|
---|
1359 | horizontal lines; each line is composed of a series of items (texts,
|
---|
1360 | bitmaps, images or spaces) arranged from left to right. For example, a
|
---|
1361 | compound image can be used to display a bitmap and a text string
|
---|
1362 | simultaneously in a Tk \class{Button} widget.
|
---|
1363 |
|
---|
1364 | % Python Demo of:
|
---|
1365 | % \ulink{Compound Image In Buttons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg.tcl}
|
---|
1366 |
|
---|
1367 | % Python Demo of:
|
---|
1368 | % \ulink{Compound Image In NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg2.tcl}
|
---|
1369 |
|
---|
1370 | % Python Demo of:
|
---|
1371 | % \ulink{Compound Image Notebook Color Tabs}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg4.tcl}
|
---|
1372 |
|
---|
1373 | % Python Demo of:
|
---|
1374 | % \ulink{Compound Image Icons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg3.tcl}
|
---|
1375 | \end{itemize}
|
---|
1376 |
|
---|
1377 |
|
---|
1378 | \subsubsection{Miscellaneous Widgets}
|
---|
1379 |
|
---|
1380 | \begin{classdesc}{InputOnly}{}
|
---|
1381 | The \ulink{InputOnly}
|
---|
1382 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixInputOnly.htm}
|
---|
1383 | widgets are to accept inputs from the user, which can be done with the
|
---|
1384 | \code{bind} command (\UNIX{} only).
|
---|
1385 | \end{classdesc}
|
---|
1386 |
|
---|
1387 | \subsubsection{Form Geometry Manager}
|
---|
1388 |
|
---|
1389 | In addition, \refmodule{Tix} augments \refmodule{Tkinter} by providing:
|
---|
1390 |
|
---|
1391 | \begin{classdesc}{Form}{}
|
---|
1392 | The \ulink{Form}
|
---|
1393 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixForm.htm}
|
---|
1394 | geometry manager based on attachment rules for all Tk widgets.
|
---|
1395 | \end{classdesc}
|
---|
1396 |
|
---|
1397 |
|
---|
1398 | %begin{latexonly}
|
---|
1399 | %\subsection{Tix Class Structure}
|
---|
1400 | %
|
---|
1401 | %\begin{figure}[hbtp]
|
---|
1402 | %\centerline{\epsfig{file=hierarchy.png,width=.9\textwidth}}
|
---|
1403 | %\vspace{.5cm}
|
---|
1404 | %\caption{The Class Hierarchy of Tix Widgets}
|
---|
1405 | %\end{figure}
|
---|
1406 | %end{latexonly}
|
---|
1407 |
|
---|
1408 | \subsection{Tix Commands}
|
---|
1409 |
|
---|
1410 | \begin{classdesc}{tixCommand}{}
|
---|
1411 | The \ulink{tix commands}
|
---|
1412 | {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tix.htm}
|
---|
1413 | provide access to miscellaneous elements of \refmodule{Tix}'s internal
|
---|
1414 | state and the \refmodule{Tix} application context. Most of the information
|
---|
1415 | manipulated by these methods pertains to the application as a whole,
|
---|
1416 | or to a screen or display, rather than to a particular window.
|
---|
1417 |
|
---|
1418 | To view the current settings, the common usage is:
|
---|
1419 | \begin{verbatim}
|
---|
1420 | import Tix
|
---|
1421 | root = Tix.Tk()
|
---|
1422 | print root.tix_configure()
|
---|
1423 | \end{verbatim}
|
---|
1424 | \end{classdesc}
|
---|
1425 |
|
---|
1426 | \begin{methoddesc}{tix_configure}{\optional{cnf,} **kw}
|
---|
1427 | Query or modify the configuration options of the Tix application
|
---|
1428 | context. If no option is specified, returns a dictionary all of the
|
---|
1429 | available options. If option is specified with no value, then the
|
---|
1430 | method returns a list describing the one named option (this list will
|
---|
1431 | be identical to the corresponding sublist of the value returned if no
|
---|
1432 | option is specified). If one or more option-value pairs are
|
---|
1433 | specified, then the method modifies the given option(s) to have the
|
---|
1434 | given value(s); in this case the method returns an empty string.
|
---|
1435 | Option may be any of the configuration options.
|
---|
1436 | \end{methoddesc}
|
---|
1437 |
|
---|
1438 | \begin{methoddesc}{tix_cget}{option}
|
---|
1439 | Returns the current value of the configuration option given by
|
---|
1440 | \var{option}. Option may be any of the configuration options.
|
---|
1441 | \end{methoddesc}
|
---|
1442 |
|
---|
1443 | \begin{methoddesc}{tix_getbitmap}{name}
|
---|
1444 | Locates a bitmap file of the name \code{name.xpm} or \code{name} in
|
---|
1445 | one of the bitmap directories (see the \method{tix_addbitmapdir()}
|
---|
1446 | method). By using \method{tix_getbitmap()}, you can avoid hard
|
---|
1447 | coding the pathnames of the bitmap files in your application. When
|
---|
1448 | successful, it returns the complete pathname of the bitmap file,
|
---|
1449 | prefixed with the character \samp{@}. The returned value can be used to
|
---|
1450 | configure the \code{bitmap} option of the Tk and Tix widgets.
|
---|
1451 | \end{methoddesc}
|
---|
1452 |
|
---|
1453 | \begin{methoddesc}{tix_addbitmapdir}{directory}
|
---|
1454 | Tix maintains a list of directories under which the
|
---|
1455 | \method{tix_getimage()} and \method{tix_getbitmap()} methods will
|
---|
1456 | search for image files. The standard bitmap directory is
|
---|
1457 | \file{\$TIX_LIBRARY/bitmaps}. The \method{tix_addbitmapdir()} method
|
---|
1458 | adds \var{directory} into this list. By using this method, the image
|
---|
1459 | files of an applications can also be located using the
|
---|
1460 | \method{tix_getimage()} or \method{tix_getbitmap()} method.
|
---|
1461 | \end{methoddesc}
|
---|
1462 |
|
---|
1463 | \begin{methoddesc}{tix_filedialog}{\optional{dlgclass}}
|
---|
1464 | Returns the file selection dialog that may be shared among different
|
---|
1465 | calls from this application. This method will create a file selection
|
---|
1466 | dialog widget when it is called the first time. This dialog will be
|
---|
1467 | returned by all subsequent calls to \method{tix_filedialog()}. An
|
---|
1468 | optional dlgclass parameter can be passed as a string to specified
|
---|
1469 | what type of file selection dialog widget is desired. Possible
|
---|
1470 | options are \code{tix}, \code{FileSelectDialog} or
|
---|
1471 | \code{tixExFileSelectDialog}.
|
---|
1472 | \end{methoddesc}
|
---|
1473 |
|
---|
1474 |
|
---|
1475 | \begin{methoddesc}{tix_getimage}{self, name}
|
---|
1476 | Locates an image file of the name \file{name.xpm}, \file{name.xbm} or
|
---|
1477 | \file{name.ppm} in one of the bitmap directories (see the
|
---|
1478 | \method{tix_addbitmapdir()} method above). If more than one file with
|
---|
1479 | the same name (but different extensions) exist, then the image type is
|
---|
1480 | chosen according to the depth of the X display: xbm images are chosen
|
---|
1481 | on monochrome displays and color images are chosen on color
|
---|
1482 | displays. By using \method{tix_getimage()}, you can avoid hard coding
|
---|
1483 | the pathnames of the image files in your application. When successful,
|
---|
1484 | this method returns the name of the newly created image, which can be
|
---|
1485 | used to configure the \code{image} option of the Tk and Tix widgets.
|
---|
1486 | \end{methoddesc}
|
---|
1487 |
|
---|
1488 | \begin{methoddesc}{tix_option_get}{name}
|
---|
1489 | Gets the options maintained by the Tix scheme mechanism.
|
---|
1490 | \end{methoddesc}
|
---|
1491 |
|
---|
1492 | \begin{methoddesc}{tix_resetoptions}{newScheme, newFontSet\optional{,
|
---|
1493 | newScmPrio}}
|
---|
1494 | Resets the scheme and fontset of the Tix application to
|
---|
1495 | \var{newScheme} and \var{newFontSet}, respectively. This affects only
|
---|
1496 | those widgets created after this call. Therefore, it is best to call
|
---|
1497 | the resetoptions method before the creation of any widgets in a Tix
|
---|
1498 | application.
|
---|
1499 |
|
---|
1500 | The optional parameter \var{newScmPrio} can be given to reset the
|
---|
1501 | priority level of the Tk options set by the Tix schemes.
|
---|
1502 |
|
---|
1503 | Because of the way Tk handles the X option database, after Tix has
|
---|
1504 | been has imported and inited, it is not possible to reset the color
|
---|
1505 | schemes and font sets using the \method{tix_config()} method.
|
---|
1506 | Instead, the \method{tix_resetoptions()} method must be used.
|
---|
1507 | \end{methoddesc}
|
---|
1508 |
|
---|
1509 |
|
---|
1510 |
|
---|
1511 | \section{\module{ScrolledText} ---
|
---|
1512 | Scrolled Text Widget}
|
---|
1513 |
|
---|
1514 | \declaremodule{standard}{ScrolledText}
|
---|
1515 | \platform{Tk}
|
---|
1516 | \modulesynopsis{Text widget with a vertical scroll bar.}
|
---|
1517 | \sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
|
---|
1518 |
|
---|
1519 | The \module{ScrolledText} module provides a class of the same name
|
---|
1520 | which implements a basic text widget which has a vertical scroll bar
|
---|
1521 | configured to do the ``right thing.'' Using the \class{ScrolledText}
|
---|
1522 | class is a lot easier than setting up a text widget and scroll bar
|
---|
1523 | directly. The constructor is the same as that of the
|
---|
1524 | \class{Tkinter.Text} class.
|
---|
1525 |
|
---|
1526 | The text widget and scrollbar are packed together in a \class{Frame},
|
---|
1527 | and the methods of the \class{Grid} and \class{Pack} geometry managers
|
---|
1528 | are acquired from the \class{Frame} object. This allows the
|
---|
1529 | \class{ScrolledText} widget to be used directly to achieve most normal
|
---|
1530 | geometry management behavior.
|
---|
1531 |
|
---|
1532 | Should more specific control be necessary, the following attributes
|
---|
1533 | are available:
|
---|
1534 |
|
---|
1535 | \begin{memberdesc}[ScrolledText]{frame}
|
---|
1536 | The frame which surrounds the text and scroll bar widgets.
|
---|
1537 | \end{memberdesc}
|
---|
1538 |
|
---|
1539 | \begin{memberdesc}[ScrolledText]{vbar}
|
---|
1540 | The scroll bar widget.
|
---|
1541 | \end{memberdesc}
|
---|
1542 |
|
---|
1543 |
|
---|
1544 | \input{libturtle}
|
---|
1545 |
|
---|
1546 |
|
---|
1547 | \section{Idle \label{idle}}
|
---|
1548 |
|
---|
1549 | %\declaremodule{standard}{idle}
|
---|
1550 | %\modulesynopsis{A Python Integrated Development Environment}
|
---|
1551 | \moduleauthor{Guido van Rossum}{guido@Python.org}
|
---|
1552 |
|
---|
1553 | Idle is the Python IDE built with the \refmodule{Tkinter} GUI toolkit.
|
---|
1554 | \index{Idle}
|
---|
1555 | \index{Python Editor}
|
---|
1556 | \index{Integrated Development Environment}
|
---|
1557 |
|
---|
1558 |
|
---|
1559 | IDLE has the following features:
|
---|
1560 |
|
---|
1561 | \begin{itemize}
|
---|
1562 | \item coded in 100\% pure Python, using the \refmodule{Tkinter} GUI toolkit
|
---|
1563 |
|
---|
1564 | \item cross-platform: works on Windows and \UNIX{} (on Mac OS, there are
|
---|
1565 | currently problems with Tcl/Tk)
|
---|
1566 |
|
---|
1567 | \item multi-window text editor with multiple undo, Python colorizing
|
---|
1568 | and many other features, e.g. smart indent and call tips
|
---|
1569 |
|
---|
1570 | \item Python shell window (a.k.a. interactive interpreter)
|
---|
1571 |
|
---|
1572 | \item debugger (not complete, but you can set breakpoints, view and step)
|
---|
1573 | \end{itemize}
|
---|
1574 |
|
---|
1575 |
|
---|
1576 | \subsection{Menus}
|
---|
1577 |
|
---|
1578 | \subsubsection{File menu}
|
---|
1579 |
|
---|
1580 | \begin{description}
|
---|
1581 | \item[New window] create a new editing window
|
---|
1582 | \item[Open...] open an existing file
|
---|
1583 | \item[Open module...] open an existing module (searches sys.path)
|
---|
1584 | \item[Class browser] show classes and methods in current file
|
---|
1585 | \item[Path browser] show sys.path directories, modules, classes and methods
|
---|
1586 | \end{description}
|
---|
1587 | \index{Class browser}
|
---|
1588 | \index{Path browser}
|
---|
1589 |
|
---|
1590 | \begin{description}
|
---|
1591 | \item[Save] save current window to the associated file (unsaved
|
---|
1592 | windows have a * before and after the window title)
|
---|
1593 |
|
---|
1594 | \item[Save As...] save current window to new file, which becomes
|
---|
1595 | the associated file
|
---|
1596 | \item[Save Copy As...] save current window to different file
|
---|
1597 | without changing the associated file
|
---|
1598 | \end{description}
|
---|
1599 |
|
---|
1600 | \begin{description}
|
---|
1601 | \item[Close] close current window (asks to save if unsaved)
|
---|
1602 | \item[Exit] close all windows and quit IDLE (asks to save if unsaved)
|
---|
1603 | \end{description}
|
---|
1604 |
|
---|
1605 |
|
---|
1606 | \subsubsection{Edit menu}
|
---|
1607 |
|
---|
1608 | \begin{description}
|
---|
1609 | \item[Undo] Undo last change to current window (max 1000 changes)
|
---|
1610 | \item[Redo] Redo last undone change to current window
|
---|
1611 | \end{description}
|
---|
1612 |
|
---|
1613 | \begin{description}
|
---|
1614 | \item[Cut] Copy selection into system-wide clipboard; then delete selection
|
---|
1615 | \item[Copy] Copy selection into system-wide clipboard
|
---|
1616 | \item[Paste] Insert system-wide clipboard into window
|
---|
1617 | \item[Select All] Select the entire contents of the edit buffer
|
---|
1618 | \end{description}
|
---|
1619 |
|
---|
1620 | \begin{description}
|
---|
1621 | \item[Find...] Open a search dialog box with many options
|
---|
1622 | \item[Find again] Repeat last search
|
---|
1623 | \item[Find selection] Search for the string in the selection
|
---|
1624 | \item[Find in Files...] Open a search dialog box for searching files
|
---|
1625 | \item[Replace...] Open a search-and-replace dialog box
|
---|
1626 | \item[Go to line] Ask for a line number and show that line
|
---|
1627 | \end{description}
|
---|
1628 |
|
---|
1629 | \begin{description}
|
---|
1630 | \item[Indent region] Shift selected lines right 4 spaces
|
---|
1631 | \item[Dedent region] Shift selected lines left 4 spaces
|
---|
1632 | \item[Comment out region] Insert \#\# in front of selected lines
|
---|
1633 | \item[Uncomment region] Remove leading \# or \#\# from selected lines
|
---|
1634 | \item[Tabify region] Turns \emph{leading} stretches of spaces into tabs
|
---|
1635 | \item[Untabify region] Turn \emph{all} tabs into the right number of spaces
|
---|
1636 | \item[Expand word] Expand the word you have typed to match another
|
---|
1637 | word in the same buffer; repeat to get a different expansion
|
---|
1638 | \item[Format Paragraph] Reformat the current blank-line-separated paragraph
|
---|
1639 | \end{description}
|
---|
1640 |
|
---|
1641 | \begin{description}
|
---|
1642 | \item[Import module] Import or reload the current module
|
---|
1643 | \item[Run script] Execute the current file in the __main__ namespace
|
---|
1644 | \end{description}
|
---|
1645 |
|
---|
1646 | \index{Import module}
|
---|
1647 | \index{Run script}
|
---|
1648 |
|
---|
1649 |
|
---|
1650 | \subsubsection{Windows menu}
|
---|
1651 |
|
---|
1652 | \begin{description}
|
---|
1653 | \item[Zoom Height] toggles the window between normal size (24x80)
|
---|
1654 | and maximum height.
|
---|
1655 | \end{description}
|
---|
1656 |
|
---|
1657 | The rest of this menu lists the names of all open windows; select one
|
---|
1658 | to bring it to the foreground (deiconifying it if necessary).
|
---|
1659 |
|
---|
1660 |
|
---|
1661 | \subsubsection{Debug menu (in the Python Shell window only)}
|
---|
1662 |
|
---|
1663 | \begin{description}
|
---|
1664 | \item[Go to file/line] look around the insert point for a filename
|
---|
1665 | and linenumber, open the file, and show the line.
|
---|
1666 | \item[Open stack viewer] show the stack traceback of the last exception
|
---|
1667 | \item[Debugger toggle] Run commands in the shell under the debugger
|
---|
1668 | \item[JIT Stack viewer toggle] Open stack viewer on traceback
|
---|
1669 | \end{description}
|
---|
1670 |
|
---|
1671 | \index{stack viewer}
|
---|
1672 | \index{debugger}
|
---|
1673 |
|
---|
1674 |
|
---|
1675 | \subsection{Basic editing and navigation}
|
---|
1676 |
|
---|
1677 | \begin{itemize}
|
---|
1678 | \item \kbd{Backspace} deletes to the left; \kbd{Del} deletes to the right
|
---|
1679 | \item Arrow keys and \kbd{Page Up}/\kbd{Page Down} to move around
|
---|
1680 | \item \kbd{Home}/\kbd{End} go to begin/end of line
|
---|
1681 | \item \kbd{C-Home}/\kbd{C-End} go to begin/end of file
|
---|
1682 | \item Some \program{Emacs} bindings may also work, including \kbd{C-B},
|
---|
1683 | \kbd{C-P}, \kbd{C-A}, \kbd{C-E}, \kbd{C-D}, \kbd{C-L}
|
---|
1684 | \end{itemize}
|
---|
1685 |
|
---|
1686 |
|
---|
1687 | \subsubsection{Automatic indentation}
|
---|
1688 |
|
---|
1689 | After a block-opening statement, the next line is indented by 4 spaces
|
---|
1690 | (in the Python Shell window by one tab). After certain keywords
|
---|
1691 | (break, return etc.) the next line is dedented. In leading
|
---|
1692 | indentation, \kbd{Backspace} deletes up to 4 spaces if they are there.
|
---|
1693 | \kbd{Tab} inserts 1-4 spaces (in the Python Shell window one tab).
|
---|
1694 | See also the indent/dedent region commands in the edit menu.
|
---|
1695 |
|
---|
1696 |
|
---|
1697 | \subsubsection{Python Shell window}
|
---|
1698 |
|
---|
1699 | \begin{itemize}
|
---|
1700 | \item \kbd{C-C} interrupts executing command
|
---|
1701 | \item \kbd{C-D} sends end-of-file; closes window if typed at
|
---|
1702 | a \samp{>>>~} prompt
|
---|
1703 | \end{itemize}
|
---|
1704 |
|
---|
1705 | \begin{itemize}
|
---|
1706 | \item \kbd{Alt-p} retrieves previous command matching what you have typed
|
---|
1707 | \item \kbd{Alt-n} retrieves next
|
---|
1708 | \item \kbd{Return} while on any previous command retrieves that command
|
---|
1709 | \item \kbd{Alt-/} (Expand word) is also useful here
|
---|
1710 | \end{itemize}
|
---|
1711 |
|
---|
1712 | \index{indentation}
|
---|
1713 |
|
---|
1714 |
|
---|
1715 | \subsection{Syntax colors}
|
---|
1716 |
|
---|
1717 | The coloring is applied in a background ``thread,'' so you may
|
---|
1718 | occasionally see uncolorized text. To change the color
|
---|
1719 | scheme, edit the \code{[Colors]} section in \file{config.txt}.
|
---|
1720 |
|
---|
1721 | \begin{description}
|
---|
1722 | \item[Python syntax colors:]
|
---|
1723 |
|
---|
1724 | \begin{description}
|
---|
1725 | \item[Keywords] orange
|
---|
1726 | \item[Strings ] green
|
---|
1727 | \item[Comments] red
|
---|
1728 | \item[Definitions] blue
|
---|
1729 | \end{description}
|
---|
1730 |
|
---|
1731 | \item[Shell colors:]
|
---|
1732 | \begin{description}
|
---|
1733 | \item[Console output] brown
|
---|
1734 | \item[stdout] blue
|
---|
1735 | \item[stderr] dark green
|
---|
1736 | \item[stdin] black
|
---|
1737 | \end{description}
|
---|
1738 | \end{description}
|
---|
1739 |
|
---|
1740 |
|
---|
1741 | \subsubsection{Command line usage}
|
---|
1742 |
|
---|
1743 | \begin{verbatim}
|
---|
1744 | idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...
|
---|
1745 |
|
---|
1746 | -c command run this command
|
---|
1747 | -d enable debugger
|
---|
1748 | -e edit mode; arguments are files to be edited
|
---|
1749 | -s run $IDLESTARTUP or $PYTHONSTARTUP first
|
---|
1750 | -t title set title of shell window
|
---|
1751 | \end{verbatim}
|
---|
1752 |
|
---|
1753 | If there are arguments:
|
---|
1754 |
|
---|
1755 | \begin{enumerate}
|
---|
1756 | \item If \programopt{-e} is used, arguments are files opened for
|
---|
1757 | editing and \code{sys.argv} reflects the arguments passed to
|
---|
1758 | IDLE itself.
|
---|
1759 |
|
---|
1760 | \item Otherwise, if \programopt{-c} is used, all arguments are
|
---|
1761 | placed in \code{sys.argv[1:...]}, with \code{sys.argv[0]} set
|
---|
1762 | to \code{'-c'}.
|
---|
1763 |
|
---|
1764 | \item Otherwise, if neither \programopt{-e} nor \programopt{-c} is
|
---|
1765 | used, the first argument is a script which is executed with
|
---|
1766 | the remaining arguments in \code{sys.argv[1:...]} and
|
---|
1767 | \code{sys.argv[0]} set to the script name. If the script name
|
---|
1768 | is '-', no script is executed but an interactive Python
|
---|
1769 | session is started; the arguments are still available in
|
---|
1770 | \code{sys.argv}.
|
---|
1771 | \end{enumerate}
|
---|
1772 |
|
---|
1773 |
|
---|
1774 | \section{Other Graphical User Interface Packages
|
---|
1775 | \label{other-gui-packages}}
|
---|
1776 |
|
---|
1777 |
|
---|
1778 | There are an number of extension widget sets to \refmodule{Tkinter}.
|
---|
1779 |
|
---|
1780 | \begin{seealso*}
|
---|
1781 | \seetitle[http://pmw.sourceforge.net/]{Python megawidgets}{is a
|
---|
1782 | toolkit for building high-level compound widgets in Python using the
|
---|
1783 | \refmodule{Tkinter} module. It consists of a set of base classes and
|
---|
1784 | a library of flexible and extensible megawidgets built on this
|
---|
1785 | foundation. These megawidgets include notebooks, comboboxes, selection
|
---|
1786 | widgets, paned widgets, scrolled widgets, dialog windows, etc. Also,
|
---|
1787 | with the Pmw.Blt interface to BLT, the busy, graph, stripchart, tabset
|
---|
1788 | and vector commands are be available.
|
---|
1789 |
|
---|
1790 | The initial ideas for Pmw were taken from the Tk \code{itcl}
|
---|
1791 | extensions \code{[incr Tk]} by Michael McLennan and \code{[incr
|
---|
1792 | Widgets]} by Mark Ulferts. Several of the megawidgets are direct
|
---|
1793 | translations from the itcl to Python. It offers most of the range of
|
---|
1794 | widgets that \code{[incr Widgets]} does, and is almost as complete as
|
---|
1795 | Tix, lacking however Tix's fast \class{HList} widget for drawing trees.
|
---|
1796 | }
|
---|
1797 |
|
---|
1798 | \seetitle[http://tkinter.effbot.org/]{Tkinter3000 Widget Construction
|
---|
1799 | Kit (WCK)}{%
|
---|
1800 | is a library that allows you to write new Tkinter widgets in pure
|
---|
1801 | Python. The WCK framework gives you full control over widget
|
---|
1802 | creation, configuration, screen appearance, and event handling. WCK
|
---|
1803 | widgets can be very fast and light-weight, since they can operate
|
---|
1804 | directly on Python data structures, without having to transfer data
|
---|
1805 | through the Tk/Tcl layer.}
|
---|
1806 | \end{seealso*}
|
---|
1807 |
|
---|
1808 | Other GUI packages are also available for Python:
|
---|
1809 |
|
---|
1810 | \begin{seealso*}
|
---|
1811 | \seetitle[http://www.wxpython.org]{wxPython}{
|
---|
1812 | wxPython is a cross-platform GUI toolkit for Python that is built
|
---|
1813 | around the popular \ulink{wxWidgets}{http://www.wxwidgets.org/} \Cpp{}
|
---|
1814 | toolkit. It provides a native look and feel for applications on
|
---|
1815 | Windows, Mac OS X, and \UNIX{} systems by using each platform's native
|
---|
1816 | widgets where ever possible, (GTK+ on \UNIX-like systems). In
|
---|
1817 | addition to an extensive set of widgets, wxPython provides classes for
|
---|
1818 | online documentation and context sensitive help, printing, HTML
|
---|
1819 | viewing, low-level device context drawing, drag and drop, system
|
---|
1820 | clipboard access, an XML-based resource format and more, including an
|
---|
1821 | ever growing library of user-contributed modules. Both the wxWidgets
|
---|
1822 | and wxPython projects are under active development and continuous
|
---|
1823 | improvement, and have active and helpful user and developer
|
---|
1824 | communities.
|
---|
1825 | }
|
---|
1826 | \seetitle[http://www.amazon.com/exec/obidos/ASIN/1932394621]
|
---|
1827 | {wxPython in Action}{
|
---|
1828 | The wxPython book, by Noel Rappin and Robin Dunn.
|
---|
1829 | }
|
---|
1830 | \seetitle{PyQt}{
|
---|
1831 | PyQt is a \program{sip}-wrapped binding to the Qt toolkit. Qt is an
|
---|
1832 | extensive \Cpp{} GUI toolkit that is available for \UNIX, Windows and
|
---|
1833 | Mac OS X. \program{sip} is a tool for generating bindings for \Cpp{}
|
---|
1834 | libraries as Python classes, and is specifically designed for Python.
|
---|
1835 | An online manual is available at
|
---|
1836 | \url{http://www.opendocspublishing.com/pyqt/} (errata are located at
|
---|
1837 | \url{http://www.valdyas.org/python/book.html}).
|
---|
1838 | }
|
---|
1839 | \seetitle[http://www.riverbankcomputing.co.uk/pykde/index.php]{PyKDE}{
|
---|
1840 | PyKDE is a \program{sip}-wrapped interface to the KDE desktop
|
---|
1841 | libraries. KDE is a desktop environment for \UNIX{} computers; the
|
---|
1842 | graphical components are based on Qt.
|
---|
1843 | }
|
---|
1844 | \seetitle[http://fxpy.sourceforge.net/]{FXPy}{
|
---|
1845 | is a Python extension module which provides an interface to the
|
---|
1846 | \citetitle[http://www.cfdrc.com/FOX/fox.html]{FOX} GUI.
|
---|
1847 | FOX is a \Cpp{} based Toolkit for developing Graphical User Interfaces
|
---|
1848 | easily and effectively. It offers a wide, and growing, collection of
|
---|
1849 | Controls, and provides state of the art facilities such as drag and
|
---|
1850 | drop, selection, as well as OpenGL widgets for 3D graphical
|
---|
1851 | manipulation. FOX also implements icons, images, and user-convenience
|
---|
1852 | features such as status line help, and tooltips.
|
---|
1853 |
|
---|
1854 | Even though FOX offers a large collection of controls already, FOX
|
---|
1855 | leverages \Cpp{} to allow programmers to easily build additional Controls
|
---|
1856 | and GUI elements, simply by taking existing controls, and creating a
|
---|
1857 | derived class which simply adds or redefines the desired behavior.
|
---|
1858 | }
|
---|
1859 | \seetitle[http://www.daa.com.au/\textasciitilde james/software/pygtk/]{PyGTK}{
|
---|
1860 | is a set of bindings for the \ulink{GTK}{http://www.gtk.org/} widget set.
|
---|
1861 | It provides an object oriented interface that is slightly higher
|
---|
1862 | level than the C one. It automatically does all the type casting and
|
---|
1863 | reference counting that you would have to do normally with the C
|
---|
1864 | API. There are also
|
---|
1865 | \ulink{bindings}{http://www.daa.com.au/\textasciitilde james/gnome/}
|
---|
1866 | to \ulink{GNOME}{http://www.gnome.org}, and a
|
---|
1867 | \ulink{tutorial}
|
---|
1868 | {http://laguna.fmedic.unam.mx/\textasciitilde daniel/pygtutorial/pygtutorial/index.html}
|
---|
1869 | is available.
|
---|
1870 | }
|
---|
1871 | \end{seealso*}
|
---|
1872 |
|
---|
1873 | % XXX Reference URLs that compare the different UI packages
|
---|