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