blob: fa5383188e60c0e7f5dbcdfbbe435f170134b129 [file] [log] [blame]
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001\chapter{Graphical User Interface Modules \label{gui}}
2
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
41interface to the Tk GUI toolkit, now maintained at ActiveState. Both
Fred Drakec37b65e2001-11-28 07:26:15 +000042Tk and \module{Tkinter} are available on most \UNIX{} platforms, as well
Fred Drake7cf4e5b2001-11-15 17:22:04 +000043as on Windows and Macintosh systems.
44
45\begin{seealso}
46\seetitle[http://www.python.org/topics/tkinter/]
47 {Python Tkinter Resources}
48 {The Python Tkinter Topic Guide provides a great
49 deal of information on using Tk from Python and links to
50 other sources of information on Tk.}
51
52\seetitle[http://www.pythonware.com/library/an-introduction-to-tkinter.htm]
53 {An Introduction to Tkinter}
54 {Fredrik Lundh's on-line reference material.}
55
56\seetitle[http://www.nmt.edu/tcc/help/pubs/lang.html]
57 {Tkinter reference: a GUI for Python}
58 {On-line reference material.}
59
60\seetitle[http://jtkinter.sourceforge.net]
61 {Tkinter for JPython}
62 {The Jython interface to Tkinter.}
63
64\seetitle[http://www.amazon.com/exec/obidos/ASIN/1884777813]
65 {Python and Tkinter Programming}
66 {The book by John Grayson (ISBN 1-884777-81-3).}
67\end{seealso}
68
69
70\subsection{Tkinter Modules}
71
Fred Drake666ca802001-11-16 06:02:55 +000072Most of the time, the \refmodule{Tkinter} module is all you really
73need, but a number of additional modules are available as well. The
74Tk interface is located in a binary module named \module{_tkinter}.
75This module contains the low-level interface to Tk, and should never
76be used directly by application programmers. It is usually a shared
77library (or DLL), but might in some cases be statically linked with
78the Python interpreter.
Fred Drake7cf4e5b2001-11-15 17:22:04 +000079
80In addition to the Tk interface module, \refmodule{Tkinter} includes a
81number of Python modules. The two most important modules are the
82\refmodule{Tkinter} module itself, and a module called
83\module{Tkconstants}. The former automatically imports the latter, so
84to use Tkinter, all you need to do is to import one module:
85
86\begin{verbatim}
87import Tkinter
88\end{verbatim}
89
90Or, more often:
91
92\begin{verbatim}
93from Tkinter import *
94\end{verbatim}
95
96\begin{classdesc}{Tk}{screenName=None, baseName=None, className='Tk'}
97The \class{Tk} class is instantiated without arguments.
98This creates a toplevel widget of Tk which usually is the main window
99of an appliation. Each instance has its own associated Tcl interpreter.
100% FIXME: The following keyword arguments are currently recognized:
101\end{classdesc}
102
103Other modules that provide Tk support include:
104
105\begin{description}
106% \declaremodule{standard}{Tkconstants}
107% \modulesynopsis{Constants used by Tkinter}
108% FIXME
109
Fred Drakec66ff202001-11-16 01:05:27 +0000110\item[\module{tkColorChooser}]
111Dialog to let the user choose a color.
112
113\item[\module{tkCommonDialog}]
114
115\item[\module{tkFileDialog}]
116Common dialogs to allow the user to specify a file to open or save.
117
118\item[\module{tkFont}]
119Utilities to help work with fonts.
120
121\item[\module{tkMessageBox}]
122Access to standard Tk dialog boxes.
123
124\item[\module{tkSimpleDialog}]
125Basic dialogs and convenience functions.
126
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000127\item[\module{Tkdnd}]
128Drag-and-drop support for \refmodule{Tkinter}.
129This is experimental and should become deprecated when it is replaced
130with the Tk DND.
131
132\item[\refmodule{turtle}]
133Turtle graphics in a Tk window.
134
135\end{description}
136
137\subsection{Tkinter Life Preserver}
Fred Drakec66ff202001-11-16 01:05:27 +0000138\sectionauthor{Matt Conway}{}
139% Converted to LaTeX by Mike Clarkson.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000140
141This section is not designed to be an exhaustive tutorial on either
142Tk or Tkinter. Rather, it is intended as a stop gap, providing some
143introductory orientation on the system.
144
145Credits:
146\begin{itemize}
147\item Tkinter was written by Steen Lumholt and Guido van Rossum.
148\item Tk was written by John Ousterhout while at Berkeley.
149\item This Life Preserver was written by Matt Conway at
150the University of Virginia.
151\item The html rendering, and some liberal editing, was
152produced from a FrameMaker version by Ken Manheimer.
153\item Fredrik Lundh elaborated and revised the class interface descriptions,
154to get them current with Tk 4.2.
155\item Mike Clarkson converted the documentation to \LaTeX, and compiled the
156User Interface chapter of the reference manual.
157\end{itemize}
158
159
160\subsubsection{How To Use This Section}
161
162This section is designed in two parts: the first half (roughly) covers
163background material, while the second half can be taken to the
164keyboard as a handy reference.
165
166When trying to answer questions of the form ``how do I do blah'', it
167is often best to find out how to do``blah'' in straight Tk, and then
168convert this back into the corresponding \refmodule{Tkinter} call.
169Python programmers can often guess at the correct Python command by
170looking at the Tk documentation. This means that in order to use
171Tkinter, you will have to know a little bit about Tk. This document
172can't fulfill that role, so the best we can do is point you to the
173best documentation that exists. Here are some hints:
174
175\begin{itemize}
176\item The authors strongly suggest getting a copy of the Tk man
177pages. Specifically, the man pages in the \code{mann} directory are most
178useful. The \code{man3} man pages describe the C interface to the Tk
179library and thus are not especially helpful for script writers.
180
181\item Addison-Wesley publishes a book called \citetitle{Tcl and the
182Tk Toolkit} by John Ousterhout (ISBN 0-201-63337-X) which is a good
183introduction to Tcl and Tk for the novice. The book is not
184exhaustive, and for many details it defers to the man pages.
185
186\item \file{Tkinter.py} is a last resort for most, but can be a good
187place to go when nothing else makes sense.
188\end{itemize}
189
190\begin{seealso}
191\seetitle[http://tcl.activestate.com/]
192 {ActiveState Tcl Home Page}
193 {The Tk/Tcl development is largely taking place at
194 ActiveState.}
195\seetitle[http://www.amazon.com/exec/obidos/ASIN/020163337X]
196 {Tcl and the Tk Toolkit}
197 {The book by John Ousterhout, the inventor of Tcl .}
198\seetitle[http://www.amazon.com/exec/obidos/ASIN/0130220280]
199 {Practical Programming in Tcl and Tk}
200 {Brent Welch's encyclopedic book.}
201\end{seealso}
202
203
204\subsubsection{A Simple Hello World Program} % HelloWorld.html
205
206%begin{latexonly}
207%\begin{figure}[hbtp]
208%\centerline{\epsfig{file=HelloWorld.gif,width=.9\textwidth}}
209%\vspace{.5cm}
210%\caption{HelloWorld gadget image}
211%\end{figure}
212%See also the hello-world \ulink{notes}{classes/HelloWorld-notes.html} and
213%\ulink{summary}{classes/HelloWorld-summary.html}.
214%end{latexonly}
215
216
217\begin{verbatim}
218from Tkinter import * 1
219 2
220class Application(Frame): 3
221 def say_hi(self): 4
222 print "hi there, everyone!" 5
223 6
224 def createWidgets(self): 7
225 self.QUIT = Button(self) 8
226 self.QUIT["text"] = "QUIT" 9
227 self.QUIT["fg"] = "red" 10
228 self.QUIT["command"] = self.quit 11
229 12
230 self.QUIT.pack({"side": "left"}) 13
231 14
232 self.hi_there = Button(self) 15
233 self.hi_there["text"] = "Hello", 16
234 self.hi_there["command"] = self.say_hi 17
235 18
236 self.hi_there.pack({"side": "left"}) 19
237 20
238 21
239 def __init__(self, master=None): 22
240 Frame.__init__(self, master) 23
241 self.pack() 24
242 self.createWidgets() 25
243 26
244app = Application() 27
245app.mainloop() 28
246\end{verbatim}
247
248\ifhtml
249\subsection{An Overview of The Tkinter Classes} % TkClassHier.html
250
251%begin{latexonly}
252%\begin{figure}[hbtp]
253%\centerline{\epsfig{file=TkClassHier.gif,width=.9\textwidth}}
254%\caption{Class Hierarchy Image}
255%\end{figure}
256%end{latexonly}
257
258The class hierarchy looks complicated, but in actual practice,
259application programmers almost always refer to the classes at the very
260bottom of the hierarchy.
261
262Here are links to the interfaces for each of the concrete widgets:
263
264\begin{itemize}
265\item \citetitle[classes/ClassButton.html]{Button}
266\item \citetitle[classes/ClassCanvas.html]{Canvas}
267\item \citetitle[classes/ClassCheckbutton.html]{Checkbutton}
268\item \citetitle[classes/ClassEntry.html]{Entry}
269\item \citetitle[classes/ClassFrame.html]{Frame}
270\item \citetitle[classes/ClassLabel.html]{Label}
271\item \citetitle[classes/ClassListbox.html]{Listbox}
272\item \citetitle[classes/ClassMenu.html]{Menu}
273\item \citetitle[classes/ClassMenubutton.html]{Menubutton}
274\item \citetitle[classes/ClassMessage.html]{Message}
275\item \citetitle[classes/ClassMisc.html]{*Misc}
276\item \citetitle[classes/ClassPacker.html]{*Pack}
277\item \citetitle[classes/ClassPlacer.html]{*Place}
278\item \citetitle[classes/ClassRadiobutton.html]{Radiobutton}
279\item \citetitle[classes/ClassScale.html]{Scale}
280\item \citetitle[classes/ClassScrollbar.html]{Scrollbar}
281\item \citetitle[classes/ClassText.html]{Text}
282\item \citetitle[classes/ClassTk.html]{**Tk}
283\item \citetitle[classes/ClassToplevel.html]{Toplevel}
284\item \citetitle[classes/ClassWidget.html]{***Widget}
285\item \citetitle[classes/ClassWm.html]{*Wm}
286\end{itemize}
287
288
289Notes:
290\begin{itemize}
291\item These classes are provided for the purposes of
292organizing certain functions under one namespace. They aren't meant to
293be instantiated independently.
294\item The Tk class is meant to be instantiated only once in
295an application. Application programmers need not instantiate one
296explicitly, the system creates one whenever any of the other classes
297are instantiated.
298\item The Widget class is not meant to be instantiated, it
Fred Drakec66ff202001-11-16 01:05:27 +0000299is meant only for subclassing to make ``real'' widgets. (in \Cpp, this
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000300is called an `abstract class')
301\end{itemize}
302\fi
303
304
305\subsection{A (Very) Quick Look at Tcl/Tk} % BriefTclTk.html
306
307To make use of this reference material, there will be times when you
308will need to know how to read short passages of Tk and how to identify
309the various parts of a Tk command.
Fred Drake666ca802001-11-16 06:02:55 +0000310(See section~\ref{tkinter-basic-mapping} for the
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000311\refmodule{Tkinter} equivalents of what's below.)
312
313Tk scripts are Tcl programs. Like all Tcl programs, Tk scripts are
314just lists of tokens separated by spaces. A Tk widget is just its
315\emph{class}, the \emph{options} that help configure it, and the
316\emph{actions} that make it do useful things.
317
318To make a widget in Tk, the command is always of the form:
319
320\begin{verbatim}
321 classCommand newPathname options
322\end{verbatim}
323
324\begin{description}
325\item[\var{classCommand}]
326denotes which kind of widget to make (a button, a label, a menu...)
327
328\item[\var{newPathname}]
329is the new name for this widget. All names in Tk must be unique. To
330help enforce this, widgets in Tk are named with \emph{pathnames}, just
331like files in a file system. The top level widget, the \emph{root},
332is called \code{.} (period) and children are delimited by more
333periods. For example, \code{.myApp.controlPanel.okButton} might be
334the name of a widget.
335
336\item[\var{options} ]
337configure the widget's appearance and in some cases, its
338behavior. The options come in the form of a list of flags and values.
339Flags are proceeded by a `-', like unix shell command flags, and
340values are put in quotes if they are more than one word.
341\end{description}
342
343For example:
344
345\begin{verbatim}
346 button .fred -fg red -text "hi there"
347 ^ ^ \_____________________/
348 | | |
349 class new options
350 command widget (-opt val -opt val ...)
351\end{verbatim}
352
353Once created, the pathname to the widget becomes a new command. This
354new \var{widget command} is the programmer's handle for getting the new
355widget to perform some \var{action}. In C, you'd express this as
Fred Drakec66ff202001-11-16 01:05:27 +0000356someAction(fred, someOptions), in \Cpp, you would express this as
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000357fred.someAction(someOptions), and in Tk, you say:
358
359\begin{verbatim}
360 .fred someAction someOptions
361\end{verbatim}
362
363Note that the object name, \code{.fred}, starts with a dot.
364
365As you'd expect, the legal values for \var{someAction} will depend on
366the widget's class: \code{.fred disable} works if fred is a
367button (fred gets greyed out), but does not work if fred is a label
368(disabling of labels is not supported in Tk).
369
370The legal values of \var{someOptions} is action dependent. Some
371actions, like \code{disable}, require no arguments, others, like
372a text-entry box's \code{delete} command, would need arguments
373to specify what range of text to delete.
374
375
376\subsection{Mapping Basic Tk into Tkinter
377 \label{tkinter-basic-mapping}}
378
379Class commands in Tk correspond to class constructors in Tkinter.
380
381\begin{verbatim}
382 button .fred =====> fred = Button()
383\end{verbatim}
384
385The master of an object is implicit in the new name given to it at
386creation time. In Tkinter, masters are specified explicitly.
387
388\begin{verbatim}
389 button .panel.fred =====> fred = Button(panel)
390\end{verbatim}
391
392The configuration options in Tk are given in lists of hyphened tags
393followed by values. In Tkinter, options are specified as
394keyword-arguments in the instance constructor, and keyword-args for
395configure calls or as instance indices, in dictionary style, for
Fred Drake666ca802001-11-16 06:02:55 +0000396established instances. See section~\ref{tkinter-setting-options} on
397setting options.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000398
399\begin{verbatim}
400 button .fred -fg red =====> fred = Button(panel, fg = "red")
401 .fred configure -fg red =====> fred["fg"] = red
402 OR ==> fred.config(fg = "red")
403\end{verbatim}
404
405In Tk, to perform an action on a widget, use the widget name as a
406command, and follow it with an action name, possibly with arguments
407(options). In Tkinter, you call methods on the class instance to
408invoke actions on the widget. The actions (methods) that a given
409widget can perform are listed in the Tkinter.py module.
410
411\begin{verbatim}
412 .fred invoke =====> fred.invoke()
413\end{verbatim}
414
415To give a widget to the packer (geometry manager), you call pack with
416optional arguments. In Tkinter, the Pack class holds all this
417functionality, and the various forms of the pack command are
418implemented as methods. All widgets in \refmodule{Tkinter} are
419subclassed from the Packer, and so inherit all the packing
420methods. See the \refmodule{Tix} module documentation for additional
421information on the Form geometry manager.
422
423\begin{verbatim}
424 pack .fred -side left =====> fred.pack(side = "left")
425\end{verbatim}
426
427
428\subsection{How Tk and Tkinter are Related} % Relationship.html
429
Fred Drake666ca802001-11-16 06:02:55 +0000430\note{This was derived from a graphical image; the image will be used
431 more directly in a subsequent version of this document.}
432
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000433From the top down:
434\begin{description}
435\item[\b{Your App Here (Python)}]
436A Python application makes a \refmodule{Tkinter} call.
437
438\item[\b{Tkinter (Python Module)}]
439This call (say, for example, creating a button widget), is
440implemented in the \emph{Tkinter} module, which is written in
441Python. This Python function will parse the commands and the
442arguments and convert them into a form that makes them look as if they
443had come from a Tk script instead of a Python script.
444
445\item[\b{tkinter (C)}]
446These commands and their arguments will be passed to a C function
447in the \emph{tkinter} - note the lowercase - extension module.
448
449\item[\b{Tk Widgets} (C and Tcl)]
450This C function is able to make calls into other C modules,
451including the C functions that make up the Tk library. Tk is
452implemented in C and some Tcl. The Tcl part of the Tk widgets is used
453to bind certain default behaviors to widgets, and is executed once at
454the point where the Python \refmodule{Tkinter} module is
455imported. (The user never sees this stage).
456
457\item[\b{Tk (C)}]
458The Tk part of the Tk Widgets implement the final mapping to ...
459
460\item[\b{Xlib (C)}]
461the Xlib library to draw graphics on the screen.
462\end{description}
463
464
465\subsection{Handy Reference}
466
467\subsubsection{Setting Options
468 \label{tkinter-setting-options}}
469
470Options control things like the color and border width of a widget.
471Options can be set in three ways:
472
473\begin{description}
474\item[At object creation time, using keyword arguments]:
475\begin{verbatim}
476fred = Button(self, fg = "red", bg = "blue")
477\end{verbatim}
478\item[After object creation, treating the option name like a dictionary index]:
479\begin{verbatim}
480fred["fg"] = "red"
481fred["bg"] = "blue"
482\end{verbatim}
483\item[Use the config() method to update multiple attrs subesequent to
484object creation]:
485\begin{verbatim}
486fred.config(fg = "red", bg = "blue")
487\end{verbatim}
488\end{description}
489
490For a complete explanation of a given option and its behavior, see the
491Tk man pages for the widget in question.
492
493Note that the man pages list "STANDARD OPTIONS" and "WIDGET SPECIFIC
494OPTIONS" for each widget. The former is a list of options that are
495common to many widgets, the latter are the options that are
496ideosyncratic to that particular widget. The Standard Options are
497documented on the \manpage{options}{3} man page.
498
499No distinction between standard and widget-specific options is made in
500this document. Some options don't apply to some kinds of widgets.
501Whether a given widget responds to a particular option depends on the
502class of the widget; buttons have a \code{command} option, labels do not.
503
504The options supported by a given widget are listed in that widget's
505man page, or can be queried at runtime by calling the
506\kbd{config()} method with arguments, or by calling the keys()
507method on that widget. The return value of these calls is a dictionary
508whose key is the name of the option (e.g. \kbd{relief}) and whose
509values are 5 tuples.
510
511(Some options, like \kbd{bg} are synonyms for common options with
512hard-to-type names (\kbd{bg} is shorthand for "background").
513Passing the \kbd{config()} method the name of a
514shorthand option will return a 2-tuple, not 5-tuple. The 2-tuple
515passed back will contain the name of the synonym ``real''
516option. (\kbd{bg}, \kbd{background}))
517
518\begin{tableiii}{c|l|l}{textrm}{Index}{Meaning}{Example}
519 \lineiii{0}{option name} {\code{'relief'}}
520 \lineiii{1}{option name for database lookup} {\code{'relief'}}
521 \lineiii{2}{option class for database lookup} {\code{'Relief'}}
522 \lineiii{3}{default value} {\code{'raised'}}
523 \lineiii{4}{current value} {\code{'groove'}}
524\end{tableiii}
525
526
527Example:
528
529\begin{verbatim}
530>>> print fred.config()
531{'relief' : ('relief', 'relief', 'Relief', 'raised', 'groove')}
532\end{verbatim}
533
534Of course, the dictionary printed will include all the options
535available and their values. This is meant only as an example.
536
537
538\subsubsection{The Packer} % Packer.html
539\index{packing (widgets)}
540
541The packer is one of Tk's geometry-management mechanisms. See also
542\citetitle[classes/ClassPacker.html]{the Packer class interface}.
543
544Geometry managers are used to specify the relative positioning of the
545positioning of widgets within their container - their mutual
546\emph{master}. In contrast to the more cumbersome \emph{placer}
547(which is used less commonly, and we do not cover here), the packer
548takes qualitative relationship specification - \emph{above}, \emph{to
549the left of}, \emph{filling}, etc - and works everything out to
550determine the exact placement coordinates for you.
551
552The size of any \emph{master} widget is determined by the size of
553the "slave widgets" inside. The packer is used to control where slave
554widgets appear inside the master into which they are packed. You can
555pack widgets into frames, and frames into other frames, in order to
556achieve the kind of layout you desire. Additionally, the arrangement
557is dynamically adjusted to accomodate incremental changes to the
558configuration, once it is packed.
559
560Note that widgets do not appear until they have had their geometry
561specified with a geometry manager. It's a common early mistake to
562leave out the geometry specification, and then be surprised when the
563widget is created but nothing appears. A widget will appear only
564after it has had, for example, the packer's \method{pack()} method
565applied to it.
566
567The pack() method can be called with keyword-option/value pairs that
568control where the widget is to appear within its container, and how it
569is to behave when the main application window is resized. Here are
570some examples:
571
572\begin{verbatim}
573 fred.pack() # defaults to side = "top"
574 fred.pack(side = "left")
575 fred.pack(expand = 1)
576\end{verbatim}
577
578
579\subsubsection{Packer Options}
580
581For more extensive information on the packer and the options that it
582can take, see the man pages and page 183 of John Ousterhout's book.
583
584\begin{description}
585\item[\b{anchor }]
586Anchor type. Denotes where the packer is to place each slave in its
587parcel.
588
589\item[\b{expand}]
590Boolean, \code{0} or \code{1}.
591
592\item[\b{fill}]
593Legal values: \code{'x'}, \code{'y'}, \code{'both'}, \code{'none'}.
594
595\item[\b{ipadx} and \b{ipady}]
596A distance - designating internal padding on each side of the slave
597widget.
598
599\item[\b{padx} and \b{pady}]
600A distance - designating external padding on each side of the slave
601widget.
602
603\item[\b{side}]
604Legal values are: \code{'left'}, \code{'right'}, \code{'top'},
605\code{'bottom'}.
606\end{description}
607
608
609\subsubsection{Coupling Widget Variables} % VarCouplings.html
610
611The current-value setting of some widgets (like text entry widgets)
612can be connected directly to application variables by using special
613options. These options are \code{variable}, \code{textvariable},
614\code{onvalue}, \code{offvalue}, and \code{value}. This
615connection works both ways: if the variable changes for any reason,
616the widget it's connected to will be updated to reflect the new value.
617
618Unfortunately, in the current implementation of \refmodule{Tkinter} it is
619not possible to hand over an arbitrary Python variable to a widget
620through a \code{variable} or \code{textvariable} option. The only
621kinds of variables for which this works are variables that are
622subclassed from a class called Variable, defined in the
623\refmodule{Tkinter} module.
624
625There are many useful subclasses of Variable already defined:
626\class{StringVar}, \class{IntVar}, \class{DoubleVar}, and
627\class{BooleanVar}. To read the current value of such a variable,
628call the \method{get()} method on
629it, and to change its value you call the \method{set()} method. If
630you follow this protocol, the widget will always track the value of
631the variable, with no further intervention on your part.
632
633For example:
634\begin{verbatim}
635class App(Frame):
636 def __init__(self, master=None):
637 Frame.__init__(self, master)
638 self.pack()
639
640 self.entrythingy = Entry()
641 self.entrythingy.pack()
642
643 self.button.pack()
644 # here is the application variable
645 self.contents = StringVar()
646 # set it to some value
647 self.contents.set("this is a variable")
648 # tell the entry widget to watch this variable
649 self.entrythingy["textvariable"] = self.contents
650
651 # and here we get a callback when the user hits return.
652 # we will have the program print out the value of the
653 # application variable when the user hits return
654 self.entrythingy.bind('<Key-Return>',
655 self.print_contents)
656
657 def print_contents(self, event):
658 print "hi. contents of entry is now ---->", \
659 self.contents.get()
660\end{verbatim}
661
662
663\subsubsection{The Window Manager} % WindowMgr.html
664\index{window manager (widgets)}
665
666In Tk, there is a utility command, \code{wm}, for interacting with the
667window manager. Options to the \code{wm} command allow you to control
668things like titles, placement, icon bitmaps, and the like. In
669\refmodule{Tkinter}, these commands have been implemented as methods
670on the \class{Wm} class. Toplevel widgets are subclassed from the
671\class{Wm} class, and so can call the \class{Wm} methods directly.
672
673%See also \citetitle[classes/ClassWm.html]{the Wm class interface}.
674
675To get at the toplevel window that contains a given widget, you can
676often just refer to the widget's master. Of course if the widget has
677been packed inside of a frame, the master won't represent a toplevel
678window. To get at the toplevel window that contains an arbitrary
679widget, you can call the \method{_root()} method. This
680method begins with an underscore to denote the fact that this function
681is part of the implementation, and not an interface to Tk functionality.
682
683Here are some examples of typical usage:
684
685\begin{verbatim}
686import Tkinter
687class App(Frame):
688 def __init__(self, master=None):
689 Frame.__init__(self, master)
690 self.pack()
691
692
693# create the application
694myapp = App()
695
696#
697# here are method calls to the window manager class
698#
699myapp.master.title("My Do-Nothing Application")
700myapp.master.maxsize(1000, 400)
701
702# start the program
703myapp.mainloop()
704\end{verbatim}
705
706
707\subsubsection{Tk Option Data Types} % OptionTypes.html
708
709\index{Tk Option Data Types}
710
711\begin{description}
712\item[anchor]
713Legal values are points of the compass: \code{"n"},
714\code{"ne"}, \code{"e"}, \code{"se"}, \code{"s"},
715\code{"sw"}, \code{"w"}, \code{"nw"}, and also
716\code{"center"}.
717
718\item[bitmap]
719There are eight built-in, named bitmaps: \code{'error'}, \code{'gray25'},
720\code{'gray50'}, \code{'hourglass'}, \code{'info'}, \code{'questhead'},
721\code{'question'}, \code{'warning'}. To specify an X bitmap
722filename, give the full path to the file, preceded with an \code{@},
723as in \code{"@/usr/contrib/bitmap/gumby.bit"}.
724
725\item[boolean]
726You can pass integers 0 or 1 or the stings \code{"yes"} or \code{"no"} .
727
728\item[callback]
729This is any Python function that takes no arguments. For example:
730\begin{verbatim}
731 def print_it():
732 print "hi there"
733 fred["command"] = print_it
734\end{verbatim}
735
736\item[color]
737Colors can be given as the names of X colors in the rgb.txt file,
738or as strings representing RGB values in 4 bit: \code{"\#RGB"}, 8
739bit: \code{"\#RRGGBB"}, 12 bit" \code{"\#RRRGGGBBB"}, or 16 bit
740\code{"\#RRRRGGGGBBBB"} ranges, where R,G,B here represent any
741legal hex digit. See page 160 of Ousterhout's book for details.
742
743\item[cursor]
744The standard X cursor names from \file{cursorfont.h} can be used,
745without the \code{XC_} prefix. For example to get a hand cursor
746(\constant{XC_hand2}), use the string \code{"hand2"}. You can also
747specify a bitmap and mask file of your own. See page 179 of
748Ousterhout's book.
749
750\item[distance]
751Screen distances can be specified in either pixels or absolute
752distances. Pixels are given as numbers and absolute distances as
753strings, with the trailing character denoting units: \code{c}
754for centimeters, \code{i} for inches, \code{m} for millimeters,
755\code{p} for printer's points. For example, 3.5 inches is expressed
756as \code{"3.5i"}.
757
758\item[font]
759Tk uses a list font name format, such as \code{\{courier 10 bold\}}.
760Font sizes with positive numbers are measured in points;
761sizes with negative numbers are measured in pixels.
762
763\item[geometry]
764This is a string of the form \samp{\var{width}x\var{height}}, where
765width and height are measured in pixels for most widgets (in
766characters for widgets displaying text). For example:
767\code{fred["geometry"] = "200x100"}.
768
769\item[justify]
770Legal values are the strings: \code{"left"},
771\code{"center"}, \code{"right"}, and \code{"fill"}.
772
773\item[region]
774This is a string with four space-delimited elements, each of
775which is a legal distance (see above). For example: \code{"2 3 4
7765"} and \code{"3i 2i 4.5i 2i"} and \code{"3c 2c 4c 10.43c"}
777are all legal regions.
778
779\item[relief]
780Determines what the border style of a widget will be. Legal
781values are: \code{"raised"}, \code{"sunken"},
782\code{"flat"}, \code{"groove"}, and \code{"ridge"}.
783
784\item[scrollcommand]
785This is almost always the \method{set()} method of some scrollbar
786widget, but can be any widget method that takes a single argument.
787Refer to the file \file{Demo/tkinter/matt/canvas-with-scrollbars.py}
788in the Python source distribution for an example.
789
790\item[wrap:]
791Must be one of: \code{"none"}, \code{"char"}, or \code{"word"}.
792\end{description}
793
794
795\subsubsection{Bindings and Events} % Bindings.html
796
797\index{bind (widgets)}
798\index{events (widgets)}
799
800The bind method from the widget command allows you to watch for
801certain events and to have a callback function trigger when that event
802type occurs. The form of the bind method is:
803
804\begin{verbatim}
805 def bind(self, sequence, func, add=''):
806\end{verbatim}
807where:
808
809\begin{description}
810\item[sequence]
811is a string that denotes the target kind of event. (See the bind
812man page and page 201 of John Ousterhout's book for details).
813
814\item[func]
815is a Python function, taking one argument, to be invoked when the
816event occurs. An Event instance will be passed as the argument.
817(Functions deployed this way are commonly known as \var{callbacks}.)
818
819\item[add]
820is optional, either \samp{} or \samp{+}. Passing an empty string
821denotes that this binding is to replace any other bindings that this
822event is associated with. Preceeding with a \samp{+} means that this
823function is to be added to the list of functions bound to this event type.
824\end{description}
825
826For example:
827\begin{verbatim}
828 def turnRed(self, event):
829 event.widget["activeforeground"] = "red"
830
831 self.button.bind("<Enter>", self.turnRed)
832\end{verbatim}
833
834Notice how the widget field of the event is being accesed in the
835\method{turnRed()} callback. This field contains the widget that
836caught the X event. The following table lists the other event fields
837you can access, and how they are denoted in Tk, which can be useful
838when referring to the Tk man pages.
839
840\begin{verbatim}
841Tk Tkinter Event Field Tk Tkinter Event Field
842-- ------------------- -- -------------------
843%f focus %A char
844%h height %E send_event
845%k keycode %K keysym
846%s state %N keysym_num
847%t time %T type
848%w width %W widget
849%x x %X x_root
850%y y %Y y_root
851\end{verbatim}
852
853
854\subsubsection{The index Parameter} % Index.html
855
856A number of widgets require``index'' parameters to be passed. These
857are used to point at a specific place in a Text widget, or to
858particular characters in an Entry widget, or to particular menu items
859in a Menu widget.
860
861\begin{description}
862\item[\b{Entry widget indexes (index, view index, etc.)}]
863Entry widgets have options that refer to character positions in the
864text being displayed. You can use these \refmodule{Tkinter} functions
865to access these special points in text widgets:
Fred Drake666ca802001-11-16 06:02:55 +0000866
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000867\begin{description}
868\item[AtEnd()]
869refers to the last position in the text
Fred Drake666ca802001-11-16 06:02:55 +0000870
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000871\item[AtInsert()]
872refers to the point where the text cursor is
Fred Drake666ca802001-11-16 06:02:55 +0000873
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000874\item[AtSelFirst()]
875indicates the beginning point of the selected text
Fred Drake666ca802001-11-16 06:02:55 +0000876
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000877\item[AtSelLast()]
878denotes the last point of the selected text and finally
Fred Drake666ca802001-11-16 06:02:55 +0000879
880\item[At(x\optional{, y})]
881refers to the character at pixel location \var{x}, \var{y} (with
882\var{y} not used in the case of a text entry widget, which contains a
883single line of text).
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000884\end{description}
885
886\item[\b{Text widget indexes}]
887The index notation for Text widgets is very rich and is best described
888in the Tk man pages.
889
890\item[\b{Menu indexes (menu.invoke(), menu.entryconfig(), etc.)}]
891
892Some options and methods for menus manipulate specific menu entries.
893Anytime a menu index is needed for an option or a parameter, you may
894pass in:
895\begin{itemize}
896\item an integer which refers to the numeric position of the entry in
897the widget, counted from the top, starting with 0;
898\item the string \code{'active'}, which refers to the menu position that is
899currently under the cursor;
900\item the string \code{"last"} which refers to the last menu
901item;
902\item An integer preceded by \code{@}, as in \code{@6}, where the integer is
903interpreted as a y pixel coordinate in the menu's coordinate system;
904\item the string \code{"none"}, which indicates no menu entry at all, most
905often used with menu.activate() to deactivate all entries, and
906finally,
907\item a text string that is pattern matched against the label of the
908menu entry, as scanned from the top of the menu to the bottom. Note
909that this index type is considered after all the others, which means
910that matches for menu items labelled \code{last}, \code{active}, or
911\code{none} may be interpreted as the above literals, instead.
912\end{itemize}
913\end{description}
914
915
Fred Drakec66ff202001-11-16 01:05:27 +0000916\section{\module{Tix} ---
917 Extension widgets for Tk}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000918
919\declaremodule{standard}{Tix}
920\modulesynopsis{Tk Extension Widgets for Tkinter}
921\sectionauthor{Mike Clarkson}{mikeclarkson@users.sourceforge.net}
922
Fred Drakec66ff202001-11-16 01:05:27 +0000923\index{Tix}
924
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000925The \module{Tix} (Tk Interface Extension) module provides an
926additional rich set of widgets. Although the standard Tk library has
927many useful widgets, they are far from complete. The \module{Tix}
928library provides most of the commonly needed widgets that are missing
929from standard Tk: \class{HList}, \class{ComboBox}, \class{Control}
930(a.k.a. SpinBox) and an assortment of scrollable widgets. \module{Tix}
931also includes many more widgets that are generally useful in a wide
932range of applications: \class{NoteBook}, \class{FileEntry},
933\class{PanedWindow}, etc; there are more than 40 of them.
934
935With all these new widgets, you can introduce new interaction
936techniques into applications, creating more useful and more intuitive
937user interfaces. You can design your application by choosing the most
938appropriate widgets to match the special needs of your application and
939users.
940
941\begin{seealso}
942\seetitle[http://tix.sourceforge.net/]
943 {Tix Homepage}
944 {See the home page for \module{Tix}.}
945\seetitle[http://tix.sourceforge.net/dist/current/man/]
946 {Tix Man Pages}
947 {On-line version of the man pages and reference material.}
948\seetitle[http://tix.sourceforge.net/dist/current/docs/tix-book/tix.book.html]
949 {Tix Programming Guide}
950 {On-line version of the programmer's reference material.}
951\seetitle[http://tix.sourceforge.net/Tide/]
952 {Tix Development Applications}
953 {Tix applications for development of Tix and Tkinter programs.
954 Tide applications work under Tk or Tkinter, and include
955 \program{TixInspect}, an inspector to remotely modify and
956 debug Tix/Tk/Tkinter applications.}
957\end{seealso}
958
959
960\subsection{Using Tix}
961
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
1349% Python Demo of: \ulink{XPM Image In Button}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm.tcl}
1350
1351% Python Demo of: \ulink{XPM Image In Menu}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm1.tcl}
1352
1353\item
1354\ulink{Compound}
Fred Drake666ca802001-11-16 06:02:55 +00001355{http://tix.sourceforge.net/dist/current/man/html/TixCmd/compound.html}
1356image types can be used to create images that consists of multiple
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001357horizontal lines; each line is composed of a series of items (texts,
1358bitmaps, images or spaces) arranged from left to right. For example, a
1359compound image can be used to display a bitmap and a text string
1360simutaneously in a Tk \class{Button} widget.
1361
Fred Drake666ca802001-11-16 06:02:55 +00001362% Python Demo of:
1363% \ulink{Compound Image In Buttons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001364
Fred Drake666ca802001-11-16 06:02:55 +00001365% Python Demo of:
1366% \ulink{Compound Image In NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001367
Fred Drake666ca802001-11-16 06:02:55 +00001368% Python Demo of:
1369% \ulink{Compound Image Notebook Color Tabs}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg4.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001370
Fred Drake666ca802001-11-16 06:02:55 +00001371% Python Demo of:
1372% \ulink{Compound Image Icons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg3.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001373\end{itemize}
1374
1375
1376\subsubsection{Miscellaneous Widgets}
1377
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001378\begin{classdesc}{InputOnly}{}
1379The \ulink{InputOnly}
Fred Drake666ca802001-11-16 06:02:55 +00001380{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixInputOnly.htm}
1381widgets are to accept inputs from the user, which can be done with the
1382\code{bind} command (\UNIX{} only).
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001383\end{classdesc}
1384
1385\subsubsection{Form Geometry Manager}
1386
1387In addition, \refmodule{Tix} augments \refmodule{Tkinter} by providing:
Fred Drake666ca802001-11-16 06:02:55 +00001388
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001389\begin{classdesc}{Form}{}
1390The \ulink{Form}
Fred Drake666ca802001-11-16 06:02:55 +00001391{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixForm.htm}
1392geometry manager based on attachment rules for all Tk widgets.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001393\end{classdesc}
1394
1395
1396%begin{latexonly}
1397%\subsection{Tix Class Structure}
1398%
1399%\begin{figure}[hbtp]
1400%\centerline{\epsfig{file=hierarchy.png,width=.9\textwidth}}
1401%\vspace{.5cm}
1402%\caption{The Class Hierarchy of Tix Widgets}
1403%\end{figure}
1404%end{latexonly}
1405
Fred Drake44b6f842001-11-29 21:09:08 +00001406\subsection{Tix Commands}
1407
1408\begin{classdesc}{tixCommand}{}
1409The \ulink{tix commands}
1410{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tix.htm}
1411provide access to miscellaneous elements of \refmodule{Tix}'s internal
1412state and the \refmodule{Tix} application context. Most of the information
1413manipulated by these methods pertains to the application as a whole,
1414or to a screen or display, rather than to a particular window.
1415
1416To view the current settings, the common usage is:
1417\begin{verbatim}
1418import Tix
1419root = Tix.Tk()
1420print root.tix_configure()
1421\end{verbatim}
1422\end{classdesc}
1423
1424\begin{methoddesc}{tix_configure}{\optional{cnf,} **kw}
1425Query or modify the configuration options of the Tix application
1426context. If no option is specified, returns a dictionary all of the
1427available options. If option is specified with no value, then the
1428method returns a list describing the one named option (this list will
1429be identical to the corresponding sublist of the value returned if no
1430option is specified). If one or more option-value pairs are
1431specified, then the method modifies the given option(s) to have the
1432given value(s); in this case the method returns an empty string.
1433Option may be any of the configuration options.
1434\end{methoddesc}
1435
1436\begin{methoddesc}{tix_cget}{option}
1437Returns the current value of the configuration option given by
1438\var{option}. Option may be any of the configuration options.
1439\end{methoddesc}
1440
1441\begin{methoddesc}{tix_getbitmap}{name}
1442Locates a bitmap file of the name \code{name.xpm} or \code{name} in
1443one of the bitmap directories (see the \method{tix_addbitmapdir()}
1444method). By using \method{tix_getbitmap()}, you can avoid hard
1445coding the pathnames of the bitmap files in your application. When
1446successful, it returns the complete pathname of the bitmap file,
1447prefixed with the character \samp{@}. The returned value can be used to
1448configure the \code{bitmap} option of the Tk and Tix widgets.
1449\end{methoddesc}
1450
1451\begin{methoddesc}{tix_addbitmapdir}{directory}
1452Tix maintains a list of directories under which the
1453\method{tix_getimage()} and \method{tix_getbitmap()} methods will
1454search for image files. The standard bitmap directory is
1455\file{\$TIX_LIBRARY/bitmaps}. The \method{tix_addbitmapdir()} method
1456adds \var{directory} into this list. By using this method, the image
1457files of an applications can also be located using the
1458\method{tix_getimage()} or \method{tix_getbitmap()} method.
1459\end{methoddesc}
1460
1461\begin{methoddesc}{tix_filedialog}{\optional{dlgclass}}
1462Returns the file selection dialog that may be shared among different
1463calls from this application. This method will create a file selection
1464dialog widget when it is called the first time. This dialog will be
1465returned by all subsequent calls to \method{tix_filedialog()}. An
1466optional dlgclass parameter can be passed as a string to specified
1467what type of file selection dialog widget is desired. Possible
1468options are \code{tix}, \code{FileSelectDialog} or
1469\code{tixExFileSelectDialog}.
1470\end{methoddesc}
1471
1472
1473\begin{methoddesc}{tix_getimage}{self, name}
1474Locates an image file of the name \file{name.xpm}, \file{name.xbm} or
1475\file{name.ppm} in one of the bitmap directories (see the
1476\method{tix_addbitmapdir()} method above). If more than one file with
1477the same name (but different extensions) exist, then the image type is
1478chosen according to the depth of the X display: xbm images are chosen
1479on monochrome displays and color images are chosen on color
1480displays. By using \method{tix_getimage()}, you can avoid hard coding
1481the pathnames of the image files in your application. When successful,
1482this method returns the name of the newly created image, which can be
1483used to configure the \code{image} option of the Tk and Tix widgets.
1484\end{methoddesc}
1485
1486\begin{methoddesc}{tix_option_get}{name}
1487Gets the options manitained by the Tix scheme mechanism.
1488\end{methoddesc}
1489
1490\begin{methoddesc}{tix_resetoptions}{newScheme, newFontSet\optional{,
1491 newScmPrio}}
1492Resets the scheme and fontset of the Tix application to
1493\var{newScheme} and \var{newFontSet}, respectively. This affects only
1494those widgets created after this call. Therefore, it is best to call
1495the resetoptions method before the creation of any widgets in a Tix
1496application.
1497
1498The optional parameter \var{newScmPrio} can be given to reset the
1499priority level of the Tk options set by the Tix schemes.
1500
1501Because of the way Tk handles the X option database, after Tix has
1502been has imported and inited, it is not possible to reset the color
1503schemes and font sets using the \method{tix_config()} method.
1504Instead, the \method{tix_resetoptions()} method must be used.
1505\end{methoddesc}
1506
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001507
Fred Drakec66ff202001-11-16 01:05:27 +00001508\input{libturtle}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001509
1510
1511\section{Idle \label{idle}}
1512
1513%\declaremodule{standard}{idle}
1514%\modulesynopsis{A Python Integrated Developement Environment}
1515\moduleauthor{Guido van Rossum}{guido@Python.org}
1516
1517Idle is the Python IDE built with the \refmodule{Tkinter} GUI toolkit.
1518\index{Idle}
1519\index{Python Editor}
1520\index{Integrated Developement Environment}
1521
1522
1523IDLE has the following features:
1524
1525\begin{itemize}
1526\item coded in 100\% pure Python, using the \refmodule{Tkinter} GUI toolkit
1527
1528\item cross-platform: works on Windows and \UNIX{} (on Mac OS, there are
1529currently problems with Tcl/Tk)
1530
1531\item multi-window text editor with multiple undo, Python colorizing
1532and many other features, e.g. smart indent and call tips
1533
1534\item Python shell window (a.k.a. interactive interpreter)
1535
1536\item debugger (not complete, but you can set breakpoints, view and step)
1537\end{itemize}
1538
1539
1540\subsection{Menus}
1541
1542\subsubsection{File menu}
1543
1544\begin{description}
1545\item[New window] create a new editing window
1546\item[Open...] open an existing file
1547\item[Open module...] open an existing module (searches sys.path)
1548\item[Class browser] show classes and methods in current file
1549\item[Path browser] show sys.path directories, modules, classes and methods
1550\end{description}
1551\index{Class browser}
1552\index{Path browser}
1553
1554\begin{description}
1555\item[Save] save current window to the associated file (unsaved
1556windows have a * before and after the window title)
1557
1558\item[Save As...] save current window to new file, which becomes
1559the associated file
1560\item[Save Copy As...] save current window to different file
1561without changing the associated file
1562\end{description}
1563
1564\begin{description}
1565\item[Close] close current window (asks to save if unsaved)
1566\item[Exit] close all windows and quit IDLE (asks to save if unsaved)
1567\end{description}
1568
1569
1570\subsubsection{Edit menu}
1571
1572\begin{description}
1573\item[Undo] Undo last change to current window (max 1000 changes)
1574\item[Redo] Redo last undone change to current window
1575\end{description}
1576
1577\begin{description}
1578\item[Cut] Copy selection into system-wide clipboard; then delete selection
1579\item[Copy] Copy selection into system-wide clipboard
1580\item[Paste] Insert system-wide clipboard into window
1581\item[Select All] Select the entire contents of the edit buffer
1582\end{description}
1583
1584\begin{description}
1585\item[Find...] Open a search dialog box with many options
1586\item[Find again] Repeat last search
1587\item[Find selection] Search for the string in the selection
1588\item[Find in Files...] Open a search dialog box for searching files
1589\item[Replace...] Open a search-and-replace dialog box
1590\item[Go to line] Ask for a line number and show that line
1591\end{description}
1592
1593\begin{description}
1594\item[Indent region] Shift selected lines right 4 spaces
1595\item[Dedent region] Shift selected lines left 4 spaces
1596\item[Comment out region] Insert \#\# in front of selected lines
1597\item[Uncomment region] Remove leading \# or \#\# from selected lines
1598\item[Tabify region] Turns \emph{leading} stretches of spaces into tabs
1599\item[Untabify region] Turn \emph{all} tabs into the right number of spaces
1600\item[Expand word] Expand the word you have typed to match another
1601 word in the same buffer; repeat to get a different expansion
1602\item[Format Paragraph] Reformat the current blank-line-separated paragraph
1603\end{description}
1604
1605\begin{description}
1606\item[Import module] Import or reload the current module
1607\item[Run script] Execute the current file in the __main__ namespace
1608\end{description}
1609
1610\index{Import module}
1611\index{Run script}
1612
1613
1614\subsubsection{Windows menu}
1615
1616\begin{description}
1617\item[Zoom Height] toggles the window between normal size (24x80)
1618 and maximum height.
1619\end{description}
1620
1621The rest of this menu lists the names of all open windows; select one
1622to bring it to the foreground (deiconifying it if necessary).
1623
1624
1625\subsubsection{Debug menu (in the Python Shell window only)}
1626
1627\begin{description}
1628\item[Go to file/line] look around the insert point for a filename
1629 and linenumber, open the file, and show the line.
1630\item[Open stack viewer] show the stack traceback of the last exception
1631\item[Debugger toggle] Run commands in the shell under the debugger
1632\item[JIT Stack viewer toggle] Open stack viewer on traceback
1633\end{description}
1634
1635\index{stack viewer}
1636\index{debugger}
1637
1638
1639\subsection{Basic editing and navigation}
1640
1641\begin{itemize}
1642\item \kbd{Backspace} deletes to the left; \kbd{Del} deletes to the right
1643\item Arrow keys and \kbd{Page Up}/\kbd{Page Down} to move around
1644\item \kbd{Home}/\kbd{End} go to begin/end of line
1645\item \kbd{C-Home}/\kbd{C-End} go to begin/end of file
1646\item Some \program{Emacs} bindings may also work, including \kbd{C-B},
1647 \kbd{C-P}, \kbd{C-A}, \kbd{C-E}, \kbd{C-D}, \kbd{C-L}
1648\end{itemize}
1649
1650
1651\subsubsection{Automatic indentation}
1652
1653After a block-opening statement, the next line is indented by 4 spaces
1654(in the Python Shell window by one tab). After certain keywords
1655(break, return etc.) the next line is dedented. In leading
1656indentation, \kbd{Backspace} deletes up to 4 spaces if they are there.
1657\kbd{Tab} inserts 1-4 spaces (in the Python Shell window one tab).
1658See also the indent/dedent region commands in the edit menu.
1659
1660
1661\subsubsection{Python Shell window}
1662
1663\begin{itemize}
1664\item \kbd{C-C} interrupts executing command
1665\item \kbd{C-D} sends end-of-file; closes window if typed at
1666a \samp{>>>~} prompt
1667\end{itemize}
1668
1669\begin{itemize}
Fred Drake666ca802001-11-16 06:02:55 +00001670\item \kbd{Alt-p} retrieves previous command matching what you have typed
1671\item \kbd{Alt-n} retrieves next
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001672\item \kbd{Return} while on any previous command retrieves that command
Fred Drake666ca802001-11-16 06:02:55 +00001673\item \kbd{Alt-/} (Expand word) is also useful here
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001674\end{itemize}
1675
1676\index{indentation}
1677
1678
1679\subsection{Syntax colors}
1680
1681The coloring is applied in a background ``thread,'' so you may
1682occasionally see uncolorized text. To change the color
1683scheme, edit the \code{[Colors]} section in \file{config.txt}.
1684
1685\begin{description}
1686\item[Python syntax colors:]
1687
1688\begin{description}
1689\item[Keywords] orange
1690\item[Strings ] green
1691\item[Comments] red
1692\item[Definitions] blue
1693\end{description}
1694
1695\item[Shell colors:]
1696\begin{description}
1697\item[Console output] brown
1698\item[stdout] blue
1699\item[stderr] dark green
1700\item[stdin] black
1701\end{description}
1702\end{description}
1703
1704
1705\subsubsection{Command line usage}
1706
1707\begin{verbatim}
1708idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...
1709
1710-c command run this command
1711-d enable debugger
1712-e edit mode; arguments are files to be edited
1713-s run $IDLESTARTUP or $PYTHONSTARTUP first
1714-t title set title of shell window
1715\end{verbatim}
1716
1717If there are arguments:
1718
1719\begin{enumerate}
1720\item If \programopt{-e} is used, arguments are files opened for
1721 editing and \code{sys.argv} reflects the arguments passed to
1722 IDLE itself.
1723
1724\item Otherwise, if \programopt{-c} is used, all arguments are
1725 placed in \code{sys.argv[1:...]}, with \code{sys.argv[0]} set
1726 to \code{'-c'}.
1727
1728\item Otherwise, if neither \programopt{-e} nor \programopt{-c} is
1729 used, the first argument is a script which is executed with
1730 the remaining arguments in \code{sys.argv[1:...]} and
1731 \code{sys.argv[0]} set to the script name. If the script name
1732 is '-', no script is executed but an interactive Python
1733 session is started; the arguments are still available in
1734 \code{sys.argv}.
1735\end{enumerate}
Fred Drakec66ff202001-11-16 01:05:27 +00001736
1737
1738\section{Other Graphical User Interface Packages
1739 \label{other-gui-packages}}
1740
1741
1742There are an number of extension widget sets to \refmodule{Tkinter}.
1743
1744\begin{seealso}
1745\seetitle[http://pmw.sourceforge.net/]{Python megawidgets}{is a
1746toolkit for building high-level compound widgets in Python using the
1747\refmodule{Tkinter} module. It consists of a set of base classes and
1748a library of flexible and extensible megawidgets built on this
1749foundation. These megawidgets include notebooks, comboboxes, selection
1750widgets, paned widgets, scrolled widgets, dialog windows, etc. Also,
1751with the Pmw.Blt interface to BLT, the busy, graph, stripchart, tabset
1752and vector commands are be available.
1753
1754The initial ideas for Pmw were taken from the Tk \code{itcl}
1755extensions \code{[incr Tk]} by Michael McLennan and \code{[incr
1756Widgets]} by Mark Ulferts. Several of the megawidgets are direct
1757translations from the itcl to Python. It offers most of the range of
1758widgets that \code{[incr Widgets]} does, and is almost as complete as
1759Tix, lacking however Tix's fast \class{HList} widget for drawing trees.
1760}
1761\seetitle[http://tkinter.effbot.org]{Tkinter3000}{
1762is a Widget Construction Kit that allows you to write new Tkinter
1763widgets in Python using Mixins. It is built on top of Tkinter,
1764and does not offer the extended range of widgets that \refmodule{Tix} does,
1765but does allow a form of building mega-widgets. The project is
1766still in the early stages.
1767}
1768\end{seealso}
1769
1770
Fred Drake666ca802001-11-16 06:02:55 +00001771Tk is not the only GUI for Python, but is however the
Fred Drakec66ff202001-11-16 01:05:27 +00001772most commonly used one.
1773
1774\begin{seealso}
1775\seetitle[http://www.wxwindows.org]{wxWindows}{
1776is a GUI toolkit that combines the most attractive attributes of Qt,
1777Tk, Motif, and GTK+ in one powerful and efficient package. It is
Fred Drakec37b65e2001-11-28 07:26:15 +00001778implemented in \Cpp. wxWindows supports two flavors of \UNIX{}
Fred Drakec66ff202001-11-16 01:05:27 +00001779implementation: GTK+ and Motif, and under Windows, it has a standard
1780Microsoft Foundation Classes (MFC) appearance, because it uses Win32
1781widgets. There is a Python class wrapper, independent of Tkinter.
1782
1783wxWindows is much richer in widgets than \refmodule{Tkinter}, with its
1784help system, sophisticated HTML and image viewers, and other
1785specialized widgets, extensive documentation, and printing capabilities.
1786}
1787\seetitle[http://www.thekompany.com]{PyKDE}{
1788PyKDE is a SIP wrapped interface to the Qt toolkit.
1789The Qt \Cpp{} toolkit lies at the heart of the KDE desktop, and the
1790Qt toolkit allows very tight integration with KDE, and also Windows
1791portability. SIP is a tool for generating bindings for \Cpp{} libraries
1792as Python classes, and is specifically designed for Python.
1793}
1794\seetitle[http://fxpy.sourceforge.net/]{FXPy}{
1795is a Python extension module which provides an interface to the
1796\citetitle[http://www.cfdrc.com/FOX/fox.html]{FOX} GUI.
1797FOX is a \Cpp{} based Toolkit for developing Graphical User Interfaces
1798easily and effectively. It offers a wide, and growing, collection of
1799Controls, and provides state of the art facilities such as drag and
1800drop, selection, as well as OpenGL widgets for 3D graphical
1801manipulation. FOX also implements icons, images, and user-convenience
1802features such as status line help, and tooltips.
1803
1804Even though FOX offers a large collection of controls already, FOX
1805leverages \Cpp{} to allow programmers to easily build additional Controls
1806and GUI elements, simply by taking existing controls, and creating a
1807derived class which simply adds or redefines the desired behavior.
1808}
1809\seetitle[http://www.daa.com.au/\~james/pygtk/]{PyGTK}{
1810is a set of bindings for the \ulink{GTK}{http://www.gtk.org/} widget set.
1811It provides an object oriented interface that is slightly higher
1812level than the C one. It automatically does all the type casting and
1813reference counting that you would have to do normally with the C
1814API. There are also \ulink{bindings}{http://www.daa.com.au/\~james/gnome/}
1815to \ulink{GNOME}{http://www.gnome.org}, and a
1816\ulink{tutorial}
1817{http://laguna.fmedic.unam.mx/\~daniel/pygtutorial/pygtutorial/index.html}
1818is available.
1819}
1820\end{seealso}
1821
1822% XXX Reference URLs that compare the different UI packages