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