blob: d0400c677d00b7ddb2f403980137f68304ac682b [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
Fred Drake666ca802001-11-16 06:02:55 +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
100of an appliation. Each instance has its own associated Tcl interpreter.
101% 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}
464\item[Use the config() method to update multiple attrs subesequent to
465object 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
522The packer is one of Tk's geometry-management mechanisms. See also
523\citetitle[classes/ClassPacker.html]{the Packer class interface}.
524
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
538is dynamically adjusted to accomodate incremental changes to the
539configuration, 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
624 self.button.pack()
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
647In Tk, there is a utility command, \code{wm}, for interacting with the
648window manager. Options to the \code{wm} command allow you to control
649things like titles, placement, icon bitmaps, and the like. In
650\refmodule{Tkinter}, these commands have been implemented as methods
651on 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
656To get at the toplevel window that contains a given widget, you can
657often just refer to the widget's master. Of course if the widget has
658been packed inside of a frame, the master won't represent a toplevel
659window. To get at the toplevel window that contains an arbitrary
660widget, you can call the \method{_root()} method. This
661method begins with an underscore to denote the fact that this function
662is part of the implementation, and not an interface to Tk functionality.
663
664Here are some examples of typical usage:
665
666\begin{verbatim}
667import Tkinter
668class App(Frame):
669 def __init__(self, master=None):
670 Frame.__init__(self, master)
671 self.pack()
672
673
674# create the application
675myapp = App()
676
677#
678# here are method calls to the window manager class
679#
680myapp.master.title("My Do-Nothing Application")
681myapp.master.maxsize(1000, 400)
682
683# start the program
684myapp.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]
694Legal 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]
700There 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
703filename, give the full path to the file, preceded with an \code{@},
704as in \code{"@/usr/contrib/bitmap/gumby.bit"}.
705
706\item[boolean]
Neal Norwitzcf57e502002-11-03 13:13:20 +0000707You can pass integers 0 or 1 or the strings \code{"yes"} or \code{"no"} .
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000708
709\item[callback]
710This 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]
718Colors can be given as the names of X colors in the rgb.txt file,
719or as strings representing RGB values in 4 bit: \code{"\#RGB"}, 8
720bit: \code{"\#RRGGBB"}, 12 bit" \code{"\#RRRGGGBBB"}, or 16 bit
721\code{"\#RRRRGGGGBBBB"} ranges, where R,G,B here represent any
722legal hex digit. See page 160 of Ousterhout's book for details.
723
724\item[cursor]
725The standard X cursor names from \file{cursorfont.h} can be used,
726without the \code{XC_} prefix. For example to get a hand cursor
727(\constant{XC_hand2}), use the string \code{"hand2"}. You can also
728specify a bitmap and mask file of your own. See page 179 of
729Ousterhout's book.
730
731\item[distance]
732Screen distances can be specified in either pixels or absolute
733distances. Pixels are given as numbers and absolute distances as
734strings, with the trailing character denoting units: \code{c}
735for centimeters, \code{i} for inches, \code{m} for millimeters,
736\code{p} for printer's points. For example, 3.5 inches is expressed
737as \code{"3.5i"}.
738
739\item[font]
740Tk uses a list font name format, such as \code{\{courier 10 bold\}}.
741Font sizes with positive numbers are measured in points;
742sizes with negative numbers are measured in pixels.
743
744\item[geometry]
745This is a string of the form \samp{\var{width}x\var{height}}, where
746width and height are measured in pixels for most widgets (in
747characters for widgets displaying text). For example:
748\code{fred["geometry"] = "200x100"}.
749
750\item[justify]
751Legal values are the strings: \code{"left"},
752\code{"center"}, \code{"right"}, and \code{"fill"}.
753
754\item[region]
755This is a string with four space-delimited elements, each of
756which is a legal distance (see above). For example: \code{"2 3 4
7575"} and \code{"3i 2i 4.5i 2i"} and \code{"3c 2c 4c 10.43c"}
758are all legal regions.
759
760\item[relief]
761Determines what the border style of a widget will be. Legal
762values are: \code{"raised"}, \code{"sunken"},
763\code{"flat"}, \code{"groove"}, and \code{"ridge"}.
764
765\item[scrollcommand]
766This is almost always the \method{set()} method of some scrollbar
767widget, but can be any widget method that takes a single argument.
768Refer to the file \file{Demo/tkinter/matt/canvas-with-scrollbars.py}
769in the Python source distribution for an example.
770
771\item[wrap:]
772Must 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
781The bind method from the widget command allows you to watch for
782certain events and to have a callback function trigger when that event
783type occurs. The form of the bind method is:
784
785\begin{verbatim}
786 def bind(self, sequence, func, add=''):
787\end{verbatim}
788where:
789
790\begin{description}
791\item[sequence]
792is a string that denotes the target kind of event. (See the bind
793man page and page 201 of John Ousterhout's book for details).
794
795\item[func]
796is a Python function, taking one argument, to be invoked when the
797event 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]
801is optional, either \samp{} or \samp{+}. Passing an empty string
802denotes that this binding is to replace any other bindings that this
803event is associated with. Preceeding with a \samp{+} means that this
804function is to be added to the list of functions bound to this event type.
805\end{description}
806
807For 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
815Notice how the widget field of the event is being accesed in the
816\method{turnRed()} callback. This field contains the widget that
817caught the X event. The following table lists the other event fields
818you can access, and how they are denoted in Tk, which can be useful
819when referring to the Tk man pages.
820
821\begin{verbatim}
822Tk 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
837A number of widgets require``index'' parameters to be passed. These
838are used to point at a specific place in a Text widget, or to
839particular characters in an Entry widget, or to particular menu items
840in a Menu widget.
841
842\begin{description}
843\item[\b{Entry widget indexes (index, view index, etc.)}]
844Entry widgets have options that refer to character positions in the
845text being displayed. You can use these \refmodule{Tkinter} functions
846to access these special points in text widgets:
Fred Drake666ca802001-11-16 06:02:55 +0000847
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000848\begin{description}
849\item[AtEnd()]
850refers to the last position in the text
Fred Drake666ca802001-11-16 06:02:55 +0000851
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000852\item[AtInsert()]
853refers to the point where the text cursor is
Fred Drake666ca802001-11-16 06:02:55 +0000854
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000855\item[AtSelFirst()]
856indicates the beginning point of the selected text
Fred Drake666ca802001-11-16 06:02:55 +0000857
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000858\item[AtSelLast()]
859denotes the last point of the selected text and finally
Fred Drake666ca802001-11-16 06:02:55 +0000860
861\item[At(x\optional{, y})]
862refers 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
864single line of text).
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000865\end{description}
866
867\item[\b{Text widget indexes}]
868The index notation for Text widgets is very rich and is best described
869in the Tk man pages.
870
871\item[\b{Menu indexes (menu.invoke(), menu.entryconfig(), etc.)}]
872
873Some options and methods for menus manipulate specific menu entries.
874Anytime a menu index is needed for an option or a parameter, you may
875pass in:
876\begin{itemize}
877\item an integer which refers to the numeric position of the entry in
878the widget, counted from the top, starting with 0;
879\item the string \code{'active'}, which refers to the menu position that is
880currently under the cursor;
881\item the string \code{"last"} which refers to the last menu
882item;
883\item An integer preceded by \code{@}, as in \code{@6}, where the integer is
884interpreted 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
886often used with menu.activate() to deactivate all entries, and
887finally,
888\item a text string that is pattern matched against the label of the
889menu entry, as scanned from the top of the menu to the bottom. Note
890that this index type is considered after all the others, which means
891that 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
Martin v. Löwisa288a232002-11-05 22:11:50 +0000896\subsubsection{Images}
897
898Bitmap/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
906Either type of image is created through either the \code{file} or the
907\code{data} option (other options are available as well).
908
Neal Norwitzfad265e2002-11-05 22:46:39 +0000909The image object can then be used wherever an \code{image} option is
Martin v. Löwisa288a232002-11-05 22:11:50 +0000910supported by some widget (e.g. labels, buttons, menus). In these
911cases, Tk will not keep a reference to the image. When the last Python
912reference to the image object is deleted, the image data is deleted as
Neal Norwitzfad265e2002-11-05 22:46:39 +0000913well, and Tk will display an empty box wherever the image was used.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000914
Fred Drakec66ff202001-11-16 01:05:27 +0000915\section{\module{Tix} ---
916 Extension widgets for Tk}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000917
918\declaremodule{standard}{Tix}
919\modulesynopsis{Tk Extension Widgets for Tkinter}
920\sectionauthor{Mike Clarkson}{mikeclarkson@users.sourceforge.net}
921
Fred Drakec66ff202001-11-16 01:05:27 +0000922\index{Tix}
923
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000924The \module{Tix} (Tk Interface Extension) module provides an
925additional rich set of widgets. Although the standard Tk library has
926many useful widgets, they are far from complete. The \module{Tix}
927library provides most of the commonly needed widgets that are missing
928from standard Tk: \class{HList}, \class{ComboBox}, \class{Control}
929(a.k.a. SpinBox) and an assortment of scrollable widgets. \module{Tix}
930also includes many more widgets that are generally useful in a wide
931range of applications: \class{NoteBook}, \class{FileEntry},
932\class{PanedWindow}, etc; there are more than 40 of them.
933
934With all these new widgets, you can introduce new interaction
935techniques into applications, creating more useful and more intuitive
936user interfaces. You can design your application by choosing the most
937appropriate widgets to match the special needs of your application and
938users.
939
940\begin{seealso}
941\seetitle[http://tix.sourceforge.net/]
942 {Tix Homepage}
Fred Drakea0b76762001-12-13 04:25:37 +0000943 {The home page for \module{Tix}. This includes links to
944 additional documentation and downloads.}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000945\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
Fred Drake666ca802001-11-16 06:02:55 +0000962\begin{classdesc}{Tix}{screenName\optional{, baseName\optional{, className}}}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000963 Toplevel widget of Tix which represents mostly the main window
964 of an application. It has an associated Tcl interpreter.
965
Fred Drake666ca802001-11-16 06:02:55 +0000966Classes 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
969module. In general, you can just import \refmodule{Tix}, and replace
970the toplevel call to \class{Tkinter.Tk} with \class{Tix.Tk}:
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000971\begin{verbatim}
972import Tix
973from Tkconstants import *
974root = Tix.Tk()
975\end{verbatim}
976\end{classdesc}
977
978To use \refmodule{Tix}, you must have the \refmodule{Tix} widgets installed,
979usually alongside your installation of the Tk widgets.
980To test your installation, try the following:
981\begin{verbatim}
982import Tix
983root = Tix.Tk()
984root.tk.eval('package require Tix')
985\end{verbatim}
986
987If this fails, you have a Tk installation problem which must be
988resolved before proceeding. Use the environment variable \envvar{TIX_LIBRARY}
989to point to the installed \refmodule{Tix} library directory, and
990make sure you have the dynamic object library (\file{tix8183.dll} or
991\file{libtix8183.so}) in the same directory that contains your Tk
992dynamic object library (\file{tk8183.dll} or \file{libtk8183.so}). The
993directory with the dynamic object library should also have a file
994called \file{pkgIndex.tcl} (case sensitive), which contains the line:
995
996\begin{verbatim}
997package 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}
1005introduces over 40 widget classes to the \refmodule{Tkinter}
1006repertoire. 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
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001015\begin{classdesc}{Balloon}{}
1016A \ulink{Balloon}
Fred Drakec66ff202001-11-16 01:05:27 +00001017{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixBalloon.htm}
1018that pops up over a widget to provide help. When the user moves the
1019cursor inside a widget to which a Balloon widget has been bound, a
1020small pop-up window with a descriptive message will be shown on the
1021screen.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001022\end{classdesc}
1023
Fred Drakec66ff202001-11-16 01:05:27 +00001024% Python Demo of:
1025% \ulink{Balloon}{http://tix.sourceforge.net/dist/current/demos/samples/Balloon.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001026
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001027\begin{classdesc}{ButtonBox}{}
1028The \ulink{ButtonBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001029{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixButtonBox.htm}
1030widget creates a box of buttons, such as is commonly used for \code{Ok
1031Cancel}.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001032\end{classdesc}
1033
Fred Drakec66ff202001-11-16 01:05:27 +00001034% Python Demo of:
1035% \ulink{ButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/BtnBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001036
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001037\begin{classdesc}{ComboBox}{}
1038The \ulink{ComboBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001039{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixComboBox.htm}
1040widget is similar to the combo box control in MS Windows. The user can
1041select a choice by either typing in the entry subwdget or selecting
1042from the listbox subwidget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001043\end{classdesc}
1044
Fred Drakec66ff202001-11-16 01:05:27 +00001045% Python Demo of:
1046% \ulink{ComboBox}{http://tix.sourceforge.net/dist/current/demos/samples/ComboBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001047
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001048\begin{classdesc}{Control}{}
1049The \ulink{Control}
Fred Drakec66ff202001-11-16 01:05:27 +00001050{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixControl.htm}
1051widget is also known as the \class{SpinBox} widget. The user can
1052adjust the value by pressing the two arrow buttons or by entering the
1053value directly into the entry. The new value will be checked against
1054the user-defined upper and lower limits.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001055\end{classdesc}
1056
Fred Drakec66ff202001-11-16 01:05:27 +00001057% Python Demo of:
1058% \ulink{Control}{http://tix.sourceforge.net/dist/current/demos/samples/Control.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001059
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001060\begin{classdesc}{LabelEntry}{}
1061The \ulink{LabelEntry}
Fred Drakec66ff202001-11-16 01:05:27 +00001062{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelEntry.htm}
1063widget packages an entry widget and a label into one mega widget. It
1064can be used be used to simplify the creation of ``entry-form'' type of
1065interface.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001066\end{classdesc}
1067
1068% Python Demo of:
1069% \ulink{LabelEntry}{http://tix.sourceforge.net/dist/current/demos/samples/LabEntry.tcl}
1070
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001071\begin{classdesc}{LabelFrame}{}
1072The \ulink{LabelFrame}
Fred Drakec66ff202001-11-16 01:05:27 +00001073{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelFrame.htm}
1074widget packages a frame widget and a label into one mega widget. To
1075create widgets inside a LabelFrame widget, one creates the new widgets
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001076relative 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
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001083\begin{classdesc}{Meter}{}
1084The \ulink{Meter}
Fred Drakec66ff202001-11-16 01:05:27 +00001085{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixMeter.htm}
1086widget can be used to show the progress of a background job which may
1087take a long time to execute.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001088\end{classdesc}
1089
1090% Python Demo of:
1091% \ulink{Meter}{http://tix.sourceforge.net/dist/current/demos/samples/Meter.tcl}
1092
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001093\begin{classdesc}{OptionMenu}{}
1094The \ulink{OptionMenu}
Fred Drakec66ff202001-11-16 01:05:27 +00001095{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixOptionMenu.htm}
1096creates a menu button of options.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001097\end{classdesc}
1098
Fred Drakec66ff202001-11-16 01:05:27 +00001099% Python Demo of:
1100% \ulink{OptionMenu}{http://tix.sourceforge.net/dist/current/demos/samples/OptMenu.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001101
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001102\begin{classdesc}{PopupMenu}{}
1103The \ulink{PopupMenu}
Fred Drakec66ff202001-11-16 01:05:27 +00001104{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPopupMenu.htm}
1105widget can be used as a replacement of the \code{tk_popup}
1106command. The advantage of the \refmodule{Tix} \class{PopupMenu} widget
1107is it requires less application code to manipulate.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001108\end{classdesc}
1109
Fred Drakec66ff202001-11-16 01:05:27 +00001110% Python Demo of:
1111% \ulink{PopupMenu}{http://tix.sourceforge.net/dist/current/demos/samples/PopMenu.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001112
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001113\begin{classdesc}{Select}{}
1114The \ulink{Select}
Fred Drakec66ff202001-11-16 01:05:27 +00001115{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixSelect.htm}
1116widget is a container of button subwidgets. It can be used to provide
1117radio-box or check-box style of selection options for the user.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001118\end{classdesc}
1119
Fred Drakec66ff202001-11-16 01:05:27 +00001120% Python Demo of:
1121% \ulink{Select}{http://tix.sourceforge.net/dist/current/demos/samples/Select.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001122
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001123\begin{classdesc}{StdButtonBox}{}
1124The \ulink{StdButtonBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001125{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixStdButtonBox.htm}
1126widget is a group of standard buttons for Motif-like dialog boxes.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001127\end{classdesc}
1128
Fred Drakec66ff202001-11-16 01:05:27 +00001129% Python Demo of:
1130% \ulink{StdButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/StdBBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001131
1132
1133\subsubsection{File Selectors}
1134
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001135\begin{classdesc}{DirList}{}
1136The \ulink{DirList}
1137{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirList.htm} widget
1138displays a list view of a directory, its previous directories and its
1139sub-directories. The user can choose one of the directories displayed
1140in the list or change to another directory.
1141\end{classdesc}
1142
Fred Drakec66ff202001-11-16 01:05:27 +00001143% Python Demo of:
1144% \ulink{DirList}{http://tix.sourceforge.net/dist/current/demos/samples/DirList.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001145
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001146\begin{classdesc}{DirTree}{}
1147The \ulink{DirTree}
Fred Drakec66ff202001-11-16 01:05:27 +00001148{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirTree.htm}
1149widget displays a tree view of a directory, its previous directories
1150and its sub-directories. The user can choose one of the directories
1151displayed in the list or change to another directory.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001152\end{classdesc}
1153
Fred Drakec66ff202001-11-16 01:05:27 +00001154% Python Demo of:
1155% \ulink{DirTree}{http://tix.sourceforge.net/dist/current/demos/samples/DirTree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001156
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001157\begin{classdesc}{DirSelectDialog}{}
1158The \ulink{DirSelectDialog}
Fred Drakec66ff202001-11-16 01:05:27 +00001159{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirSelectDialog.htm}
1160widget presents the directories in the file system in a dialog
1161window. The user can use this dialog window to navigate through the
1162file system to select the desired directory.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001163\end{classdesc}
1164
Fred Drakec66ff202001-11-16 01:05:27 +00001165% Python Demo of:
1166% \ulink{DirSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/DirDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001167
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001168\begin{classdesc}{DirSelectBox}{}
1169The \class{DirSelectBox} is similar
1170to the standard Motif(TM) directory-selection box. It is generally used for
1171the user to choose a directory. DirSelectBox stores the directories mostly
1172recently selected into a ComboBox widget so that they can be quickly
1173selected again.
1174\end{classdesc}
1175
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001176\begin{classdesc}{ExFileSelectBox}{}
1177The \ulink{ExFileSelectBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001178{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixExFileSelectBox.htm}
1179widget is usually embedded in a tixExFileSelectDialog widget. It
1180provides an convenient method for the user to select files. The style
1181of the \class{ExFileSelectBox} widget is very similar to the standard
1182file dialog on MS Windows 3.1.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001183\end{classdesc}
1184
Fred Drakec66ff202001-11-16 01:05:27 +00001185% Python Demo of:
1186%\ulink{ExFileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/EFileDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001187
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001188\begin{classdesc}{FileSelectBox}{}
1189The \ulink{FileSelectBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001190{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileSelectBox.htm}
1191is similar to the standard Motif(TM) file-selection box. It is
1192generally used for the user to choose a file. FileSelectBox stores the
1193files mostly recently selected into a \class{ComboBox} widget so that
1194they can be quickly selected again.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001195\end{classdesc}
1196
Fred Drakec66ff202001-11-16 01:05:27 +00001197% Python Demo of:
1198% \ulink{FileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/FileDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001199
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001200\begin{classdesc}{FileEntry}{}
1201The \ulink{FileEntry}
Fred Drakec66ff202001-11-16 01:05:27 +00001202{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileEntry.htm}
1203widget can be used to input a filename. The user can type in the
1204filename manually. Alternatively, the user can press the button widget
1205that sits next to the entry, which will bring up a file selection
1206dialog.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001207\end{classdesc}
1208
Fred Drakec66ff202001-11-16 01:05:27 +00001209% Python Demo of:
1210% \ulink{FileEntry}{http://tix.sourceforge.net/dist/current/demos/samples/FileEnt.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001211
1212
1213\subsubsection{Hierachical ListBox}
1214
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001215\begin{classdesc}{HList}{}
1216The \ulink{HList}
Fred Drakec66ff202001-11-16 01:05:27 +00001217{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixHList.htm}
1218widget can be used to display any data that have a hierarchical
1219structure, for example, file system directory trees. The list entries
1220are indented and connected by branch lines according to their places
1221in the hierachy.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001222\end{classdesc}
1223
Fred Drakec66ff202001-11-16 01:05:27 +00001224% Python Demo of:
1225% \ulink{HList}{http://tix.sourceforge.net/dist/current/demos/samples/HList1.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001226
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001227\begin{classdesc}{CheckList}{}
1228The \ulink{CheckList}
Fred Drakec66ff202001-11-16 01:05:27 +00001229{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixCheckList.htm}
1230widget displays a list of items to be selected by the user. CheckList
1231acts similarly to the Tk checkbutton or radiobutton widgets, except it
1232is capable of handling many more items than checkbuttons or
1233radiobuttons.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001234\end{classdesc}
1235
Fred Drakec66ff202001-11-16 01:05:27 +00001236% 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}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001242
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001243\begin{classdesc}{Tree}{}
1244The \ulink{Tree}
Fred Drakec66ff202001-11-16 01:05:27 +00001245{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTree.htm}
1246widget can be used to display hierachical data in a tree form. The
1247user can adjust the view of the tree by opening or closing parts of
1248the tree.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001249\end{classdesc}
1250
Fred Drakec66ff202001-11-16 01:05:27 +00001251% Python Demo of:
1252% \ulink{Tree}{http://tix.sourceforge.net/dist/current/demos/samples/Tree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001253
Fred Drakec66ff202001-11-16 01:05:27 +00001254% Python Demo of:
1255% \ulink{Tree (Dynamic)}{http://tix.sourceforge.net/dist/current/demos/samples/DynTree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001256
1257
1258\subsubsection{Tabular ListBox}
1259
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001260\begin{classdesc}{TList}{}
1261The \ulink{TList}
Fred Drakec66ff202001-11-16 01:05:27 +00001262{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTList.htm}
1263widget can be used to display data in a tabular format. The list
1264entries of a \class{TList} widget are similar to the entries in the Tk
1265listbox widget. The main differences are (1) the \class{TList} widget
1266can display the list entries in a two dimensional format and (2) you
1267can use graphical images as well as multiple colors and fonts for the
1268list entries.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001269\end{classdesc}
1270
Fred Drakec66ff202001-11-16 01:05:27 +00001271% 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}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001275
1276% Grid has yet to be added to Python
1277% \subsubsection{Grid Widget}
Fred Drakec66ff202001-11-16 01:05:27 +00001278% 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}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001284
1285
1286\subsubsection{Manager Widgets}
1287
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001288\begin{classdesc}{PanedWindow}{}
1289The \ulink{PanedWindow}
Fred Drakec66ff202001-11-16 01:05:27 +00001290{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPanedWindow.htm}
1291widget allows the user to interactively manipulate the sizes of
1292several panes. The panes can be arranged either vertically or
1293horizontally. The user changes the sizes of the panes by dragging the
1294resize handle between two panes.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001295\end{classdesc}
1296
Fred Drakec66ff202001-11-16 01:05:27 +00001297% Python Demo of:
1298% \ulink{PanedWindow}{http://tix.sourceforge.net/dist/current/demos/samples/PanedWin.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001299
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001300\begin{classdesc}{ListNoteBook}{}
1301The \ulink{ListNoteBook}
Fred Drakec66ff202001-11-16 01:05:27 +00001302{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixListNoteBook.htm}
1303widget is very similar to the \class{TixNoteBook} widget: it can be
1304used to display many windows in a limited space using a notebook
1305metaphor. The notebook is divided into a stack of pages (windows). At
1306one time only one of these pages can be shown. The user can navigate
1307through these pages by choosing the name of the desired page in the
1308\member{hlist} subwidget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001309\end{classdesc}
1310
Fred Drakec66ff202001-11-16 01:05:27 +00001311% Python Demo of:
1312% \ulink{ListNoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/ListNBK.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001313
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001314\begin{classdesc}{NoteBook}{}
1315The \ulink{NoteBook}
Fred Drakec66ff202001-11-16 01:05:27 +00001316{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixNoteBook.htm}
1317widget can be used to display many windows in a limited space using a
1318notebook metaphor. The notebook is divided into a stack of pages. At
1319one time only one of these pages can be shown. The user can navigate
1320through these pages by choosing the visual ``tabs'' at the top of the
1321NoteBook widget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001322\end{classdesc}
1323
Fred Drakec66ff202001-11-16 01:05:27 +00001324% Python Demo of:
1325% \ulink{NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/NoteBook.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001326
1327
1328% \subsubsection{Scrolled Widgets}
Fred Drakec66ff202001-11-16 01:05:27 +00001329% 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}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001337
1338
1339\subsubsection{Image Types}
1340
1341The \refmodule{Tix} module adds:
1342\begin{itemize}
1343\item
1344\ulink{pixmap}
Fred Drake666ca802001-11-16 06:02:55 +00001345{http://tix.sourceforge.net/dist/current/man/html/TixCmd/pixmap.htm}
1346capabilities to all \refmodule{Tix} and \refmodule{Tkinter} widgets to
1347create color images from XPM files.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001348
Fred Drakea0b76762001-12-13 04:25:37 +00001349% Python Demo of:
1350% \ulink{XPM Image In Button}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001351
Fred Drakea0b76762001-12-13 04:25:37 +00001352% Python Demo of:
1353% \ulink{XPM Image In Menu}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm1.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001354
1355\item
1356\ulink{Compound}
Fred Drake666ca802001-11-16 06:02:55 +00001357{http://tix.sourceforge.net/dist/current/man/html/TixCmd/compound.html}
1358image types can be used to create images that consists of multiple
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001359horizontal lines; each line is composed of a series of items (texts,
1360bitmaps, images or spaces) arranged from left to right. For example, a
1361compound image can be used to display a bitmap and a text string
1362simutaneously in a Tk \class{Button} widget.
1363
Fred Drake666ca802001-11-16 06:02:55 +00001364% Python Demo of:
1365% \ulink{Compound Image In Buttons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001366
Fred Drake666ca802001-11-16 06:02:55 +00001367% Python Demo of:
1368% \ulink{Compound Image In NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001369
Fred Drake666ca802001-11-16 06:02:55 +00001370% Python Demo of:
1371% \ulink{Compound Image Notebook Color Tabs}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg4.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001372
Fred Drake666ca802001-11-16 06:02:55 +00001373% Python Demo of:
1374% \ulink{Compound Image Icons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg3.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001375\end{itemize}
1376
1377
1378\subsubsection{Miscellaneous Widgets}
1379
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001380\begin{classdesc}{InputOnly}{}
1381The \ulink{InputOnly}
Fred Drake666ca802001-11-16 06:02:55 +00001382{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixInputOnly.htm}
1383widgets are to accept inputs from the user, which can be done with the
1384\code{bind} command (\UNIX{} only).
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001385\end{classdesc}
1386
1387\subsubsection{Form Geometry Manager}
1388
1389In addition, \refmodule{Tix} augments \refmodule{Tkinter} by providing:
Fred Drake666ca802001-11-16 06:02:55 +00001390
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001391\begin{classdesc}{Form}{}
1392The \ulink{Form}
Fred Drake666ca802001-11-16 06:02:55 +00001393{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixForm.htm}
1394geometry manager based on attachment rules for all Tk widgets.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001395\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
Fred Drake44b6f842001-11-29 21:09:08 +00001408\subsection{Tix Commands}
1409
1410\begin{classdesc}{tixCommand}{}
1411The \ulink{tix commands}
1412{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tix.htm}
1413provide access to miscellaneous elements of \refmodule{Tix}'s internal
1414state and the \refmodule{Tix} application context. Most of the information
1415manipulated by these methods pertains to the application as a whole,
1416or to a screen or display, rather than to a particular window.
1417
1418To view the current settings, the common usage is:
1419\begin{verbatim}
1420import Tix
1421root = Tix.Tk()
1422print root.tix_configure()
1423\end{verbatim}
1424\end{classdesc}
1425
1426\begin{methoddesc}{tix_configure}{\optional{cnf,} **kw}
1427Query or modify the configuration options of the Tix application
1428context. If no option is specified, returns a dictionary all of the
1429available options. If option is specified with no value, then the
1430method returns a list describing the one named option (this list will
1431be identical to the corresponding sublist of the value returned if no
1432option is specified). If one or more option-value pairs are
1433specified, then the method modifies the given option(s) to have the
1434given value(s); in this case the method returns an empty string.
1435Option may be any of the configuration options.
1436\end{methoddesc}
1437
1438\begin{methoddesc}{tix_cget}{option}
1439Returns 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}
1444Locates a bitmap file of the name \code{name.xpm} or \code{name} in
1445one of the bitmap directories (see the \method{tix_addbitmapdir()}
1446method). By using \method{tix_getbitmap()}, you can avoid hard
1447coding the pathnames of the bitmap files in your application. When
1448successful, it returns the complete pathname of the bitmap file,
1449prefixed with the character \samp{@}. The returned value can be used to
1450configure the \code{bitmap} option of the Tk and Tix widgets.
1451\end{methoddesc}
1452
1453\begin{methoddesc}{tix_addbitmapdir}{directory}
1454Tix maintains a list of directories under which the
1455\method{tix_getimage()} and \method{tix_getbitmap()} methods will
1456search for image files. The standard bitmap directory is
1457\file{\$TIX_LIBRARY/bitmaps}. The \method{tix_addbitmapdir()} method
1458adds \var{directory} into this list. By using this method, the image
1459files 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}}
1464Returns the file selection dialog that may be shared among different
1465calls from this application. This method will create a file selection
1466dialog widget when it is called the first time. This dialog will be
1467returned by all subsequent calls to \method{tix_filedialog()}. An
1468optional dlgclass parameter can be passed as a string to specified
1469what type of file selection dialog widget is desired. Possible
1470options are \code{tix}, \code{FileSelectDialog} or
1471\code{tixExFileSelectDialog}.
1472\end{methoddesc}
1473
1474
1475\begin{methoddesc}{tix_getimage}{self, name}
1476Locates 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
1479the same name (but different extensions) exist, then the image type is
1480chosen according to the depth of the X display: xbm images are chosen
1481on monochrome displays and color images are chosen on color
1482displays. By using \method{tix_getimage()}, you can avoid hard coding
1483the pathnames of the image files in your application. When successful,
1484this method returns the name of the newly created image, which can be
1485used to configure the \code{image} option of the Tk and Tix widgets.
1486\end{methoddesc}
1487
1488\begin{methoddesc}{tix_option_get}{name}
1489Gets the options manitained by the Tix scheme mechanism.
1490\end{methoddesc}
1491
1492\begin{methoddesc}{tix_resetoptions}{newScheme, newFontSet\optional{,
1493 newScmPrio}}
1494Resets the scheme and fontset of the Tix application to
1495\var{newScheme} and \var{newFontSet}, respectively. This affects only
1496those widgets created after this call. Therefore, it is best to call
1497the resetoptions method before the creation of any widgets in a Tix
1498application.
1499
1500The optional parameter \var{newScmPrio} can be given to reset the
1501priority level of the Tk options set by the Tix schemes.
1502
1503Because of the way Tk handles the X option database, after Tix has
1504been has imported and inited, it is not possible to reset the color
1505schemes and font sets using the \method{tix_config()} method.
1506Instead, the \method{tix_resetoptions()} method must be used.
1507\end{methoddesc}
1508
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001509
Fred Drake1a763862001-12-03 21:18:30 +00001510
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
1519The \module{ScrolledText} module provides a class of the same name
1520which implements a basic text widget which has a vertical scroll bar
1521configured to do the ``right thing.'' Using the \class{ScrolledText}
1522class is a lot easier than setting up a text widget and scroll bar
1523directly. The constructor is the same as that of the
1524\class{Tkinter.Text} class.
1525
1526The text widget and scrollbar are packed together in a \class{Frame},
Fred Drakea0b76762001-12-13 04:25:37 +00001527and the methods of the \class{Grid} and \class{Pack} geometry managers
1528are acquired from the \class{Frame} object. This allows the
1529\class{ScrolledText} widget to be used directly to achieve most normal
1530geometry management behavior.
Fred Drake1a763862001-12-03 21:18:30 +00001531
1532Should more specific control be necessary, the following attributes
1533are 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
Fred Drakec66ff202001-11-16 01:05:27 +00001544\input{libturtle}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001545
1546
1547\section{Idle \label{idle}}
1548
1549%\declaremodule{standard}{idle}
1550%\modulesynopsis{A Python Integrated Developement Environment}
1551\moduleauthor{Guido van Rossum}{guido@Python.org}
1552
1553Idle is the Python IDE built with the \refmodule{Tkinter} GUI toolkit.
1554\index{Idle}
1555\index{Python Editor}
1556\index{Integrated Developement Environment}
1557
1558
1559IDLE 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
1565currently problems with Tcl/Tk)
1566
1567\item multi-window text editor with multiple undo, Python colorizing
1568and 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
1592windows have a * before and after the window title)
1593
1594\item[Save As...] save current window to new file, which becomes
1595the associated file
1596\item[Save Copy As...] save current window to different file
1597without 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
1657The rest of this menu lists the names of all open windows; select one
1658to 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
1689After 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
1692indentation, \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).
1694See 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
1702a \samp{>>>~} prompt
1703\end{itemize}
1704
1705\begin{itemize}
Fred Drake666ca802001-11-16 06:02:55 +00001706\item \kbd{Alt-p} retrieves previous command matching what you have typed
1707\item \kbd{Alt-n} retrieves next
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001708\item \kbd{Return} while on any previous command retrieves that command
Fred Drake666ca802001-11-16 06:02:55 +00001709\item \kbd{Alt-/} (Expand word) is also useful here
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001710\end{itemize}
1711
1712\index{indentation}
1713
1714
1715\subsection{Syntax colors}
1716
1717The coloring is applied in a background ``thread,'' so you may
1718occasionally see uncolorized text. To change the color
1719scheme, 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}
1744idle.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
1753If 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}
Fred Drakec66ff202001-11-16 01:05:27 +00001772
1773
1774\section{Other Graphical User Interface Packages
1775 \label{other-gui-packages}}
1776
1777
1778There are an number of extension widget sets to \refmodule{Tkinter}.
1779
Fred Drake10cd3152001-11-30 18:17:24 +00001780\begin{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001781\seetitle[http://pmw.sourceforge.net/]{Python megawidgets}{is a
1782toolkit for building high-level compound widgets in Python using the
1783\refmodule{Tkinter} module. It consists of a set of base classes and
1784a library of flexible and extensible megawidgets built on this
1785foundation. These megawidgets include notebooks, comboboxes, selection
1786widgets, paned widgets, scrolled widgets, dialog windows, etc. Also,
1787with the Pmw.Blt interface to BLT, the busy, graph, stripchart, tabset
1788and vector commands are be available.
1789
1790The initial ideas for Pmw were taken from the Tk \code{itcl}
1791extensions \code{[incr Tk]} by Michael McLennan and \code{[incr
1792Widgets]} by Mark Ulferts. Several of the megawidgets are direct
1793translations from the itcl to Python. It offers most of the range of
1794widgets that \code{[incr Widgets]} does, and is almost as complete as
1795Tix, lacking however Tix's fast \class{HList} widget for drawing trees.
1796}
Fred Drake81209952003-07-08 13:44:27 +00001797
1798\seetitle[http://tkinter.effbot.org/]{Tkinter3000 Widget Construction
1799 Kit (WCK)}{%
1800is a library that allows you to write new Tkinter widgets in pure
1801Python. The WCK framework gives you full control over widget
1802creation, configuration, screen appearance, and event handling. WCK
1803widgets can be very fast and light-weight, since they can operate
1804directly on Python data structures, without having to transfer data
1805through the Tk/Tcl layer.}
Fred Drake10cd3152001-11-30 18:17:24 +00001806\end{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001807
1808
Fred Drake666ca802001-11-16 06:02:55 +00001809Tk is not the only GUI for Python, but is however the
Fred Drakec66ff202001-11-16 01:05:27 +00001810most commonly used one.
1811
Fred Drake10cd3152001-11-30 18:17:24 +00001812\begin{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001813\seetitle[http://www.wxwindows.org]{wxWindows}{
1814is a GUI toolkit that combines the most attractive attributes of Qt,
1815Tk, Motif, and GTK+ in one powerful and efficient package. It is
Fred Drakec37b65e2001-11-28 07:26:15 +00001816implemented in \Cpp. wxWindows supports two flavors of \UNIX{}
Fred Drakec66ff202001-11-16 01:05:27 +00001817implementation: GTK+ and Motif, and under Windows, it has a standard
1818Microsoft Foundation Classes (MFC) appearance, because it uses Win32
1819widgets. There is a Python class wrapper, independent of Tkinter.
1820
1821wxWindows is much richer in widgets than \refmodule{Tkinter}, with its
1822help system, sophisticated HTML and image viewers, and other
1823specialized widgets, extensive documentation, and printing capabilities.
1824}
Fred Drake9b414ac2002-05-31 18:21:56 +00001825\seetitle[]{PyQt}{
1826PyQt is a \program{sip}-wrapped binding to the Qt toolkit. Qt is an
1827extensive \Cpp{} GUI toolkit that is available for \UNIX, Windows and
1828Mac OS X. \program{sip} is a tool for generating bindings for \Cpp{}
1829libraries as Python classes, and is specifically designed for Python.
1830An online manual is available at
1831\url{http://www.opendocspublishing.com/pyqt/} (errata are located at
1832\url{http://www.valdyas.org/python/book.html}).
1833}
1834\seetitle[http://www.riverbankcomputing.co.uk/pykde/index.php]{PyKDE}{
1835PyKDE is a \program{sip}-wrapped interface to the KDE desktop
1836libraries. KDE is a desktop environment for \UNIX{} computers; the
1837graphical components are based on Qt.
Fred Drakec66ff202001-11-16 01:05:27 +00001838}
1839\seetitle[http://fxpy.sourceforge.net/]{FXPy}{
1840is a Python extension module which provides an interface to the
1841\citetitle[http://www.cfdrc.com/FOX/fox.html]{FOX} GUI.
1842FOX is a \Cpp{} based Toolkit for developing Graphical User Interfaces
1843easily and effectively. It offers a wide, and growing, collection of
1844Controls, and provides state of the art facilities such as drag and
1845drop, selection, as well as OpenGL widgets for 3D graphical
1846manipulation. FOX also implements icons, images, and user-convenience
1847features such as status line help, and tooltips.
1848
1849Even though FOX offers a large collection of controls already, FOX
1850leverages \Cpp{} to allow programmers to easily build additional Controls
1851and GUI elements, simply by taking existing controls, and creating a
1852derived class which simply adds or redefines the desired behavior.
1853}
Fred Draked50bd6c2003-07-28 14:39:13 +00001854\seetitle[http://www.daa.com.au/\textasciitilde james/software/pygtk/]{PyGTK}{
Fred Drakec66ff202001-11-16 01:05:27 +00001855is a set of bindings for the \ulink{GTK}{http://www.gtk.org/} widget set.
1856It provides an object oriented interface that is slightly higher
1857level than the C one. It automatically does all the type casting and
1858reference counting that you would have to do normally with the C
Fred Drake16ecb212002-10-12 15:02:46 +00001859API. There are also
1860\ulink{bindings}{http://www.daa.com.au/\textasciitilde james/gnome/}
Fred Drakec66ff202001-11-16 01:05:27 +00001861to \ulink{GNOME}{http://www.gnome.org}, and a
1862\ulink{tutorial}
Fred Drake16ecb212002-10-12 15:02:46 +00001863{http://laguna.fmedic.unam.mx/\textasciitilde daniel/pygtutorial/pygtutorial/index.html}
Fred Drakec66ff202001-11-16 01:05:27 +00001864is available.
1865}
Fred Drake10cd3152001-11-30 18:17:24 +00001866\end{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001867
1868% XXX Reference URLs that compare the different UI packages