blob: e0c613f28aa083d6de6b0d78b85be2f68c8fb486 [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}
Fred Drakee5a55512003-05-20 15:21:08 +0000223from Tkinter import *
224
225class Application(Frame):
226 def say_hi(self):
227 print "hi there, everyone!"
228
229 def createWidgets(self):
230 self.QUIT = Button(self)
231 self.QUIT["text"] = "QUIT"
232 self.QUIT["fg"] = "red"
233 self.QUIT["command"] = self.quit
234
235 self.QUIT.pack({"side": "left"})
236
237 self.hi_there = Button(self)
238 self.hi_there["text"] = "Hello",
239 self.hi_there["command"] = self.say_hi
240
241 self.hi_there.pack({"side": "left"})
242
243 def __init__(self, master=None):
244 Frame.__init__(self, master)
245 self.pack()
246 self.createWidgets()
247
248app = Application()
249app.mainloop()
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000250\end{verbatim}
251
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000252
Fred Drakeb22c6722001-12-03 06:12:23 +0000253\subsection{A (Very) Quick Look at Tcl/Tk} % BriefTclTk.html
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000254
255The class hierarchy looks complicated, but in actual practice,
256application programmers almost always refer to the classes at the very
257bottom of the hierarchy.
258
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000259Notes:
260\begin{itemize}
261\item These classes are provided for the purposes of
262organizing certain functions under one namespace. They aren't meant to
263be instantiated independently.
Fred Drakeb22c6722001-12-03 06:12:23 +0000264
265\item The \class{Tk} class is meant to be instantiated only once in
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000266an application. Application programmers need not instantiate one
267explicitly, the system creates one whenever any of the other classes
268are instantiated.
Fred Drakeb22c6722001-12-03 06:12:23 +0000269
270\item The \class{Widget} class is not meant to be instantiated, it
271is meant only for subclassing to make ``real'' widgets (in \Cpp, this
272is called an `abstract class').
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000273\end{itemize}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000274
275To make use of this reference material, there will be times when you
276will need to know how to read short passages of Tk and how to identify
277the various parts of a Tk command.
Fred Drake666ca802001-11-16 06:02:55 +0000278(See section~\ref{tkinter-basic-mapping} for the
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000279\refmodule{Tkinter} equivalents of what's below.)
280
281Tk scripts are Tcl programs. Like all Tcl programs, Tk scripts are
282just lists of tokens separated by spaces. A Tk widget is just its
283\emph{class}, the \emph{options} that help configure it, and the
284\emph{actions} that make it do useful things.
285
286To make a widget in Tk, the command is always of the form:
287
288\begin{verbatim}
289 classCommand newPathname options
290\end{verbatim}
291
292\begin{description}
293\item[\var{classCommand}]
294denotes which kind of widget to make (a button, a label, a menu...)
295
296\item[\var{newPathname}]
297is the new name for this widget. All names in Tk must be unique. To
298help enforce this, widgets in Tk are named with \emph{pathnames}, just
299like files in a file system. The top level widget, the \emph{root},
300is called \code{.} (period) and children are delimited by more
301periods. For example, \code{.myApp.controlPanel.okButton} might be
302the name of a widget.
303
304\item[\var{options} ]
305configure the widget's appearance and in some cases, its
306behavior. The options come in the form of a list of flags and values.
307Flags are proceeded by a `-', like unix shell command flags, and
308values are put in quotes if they are more than one word.
309\end{description}
310
311For example:
312
313\begin{verbatim}
314 button .fred -fg red -text "hi there"
315 ^ ^ \_____________________/
316 | | |
317 class new options
318 command widget (-opt val -opt val ...)
319\end{verbatim}
320
321Once created, the pathname to the widget becomes a new command. This
322new \var{widget command} is the programmer's handle for getting the new
323widget to perform some \var{action}. In C, you'd express this as
Fred Drakec66ff202001-11-16 01:05:27 +0000324someAction(fred, someOptions), in \Cpp, you would express this as
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000325fred.someAction(someOptions), and in Tk, you say:
326
327\begin{verbatim}
328 .fred someAction someOptions
329\end{verbatim}
330
331Note that the object name, \code{.fred}, starts with a dot.
332
333As you'd expect, the legal values for \var{someAction} will depend on
334the widget's class: \code{.fred disable} works if fred is a
335button (fred gets greyed out), but does not work if fred is a label
336(disabling of labels is not supported in Tk).
337
338The legal values of \var{someOptions} is action dependent. Some
339actions, like \code{disable}, require no arguments, others, like
340a text-entry box's \code{delete} command, would need arguments
341to specify what range of text to delete.
342
343
344\subsection{Mapping Basic Tk into Tkinter
345 \label{tkinter-basic-mapping}}
346
347Class commands in Tk correspond to class constructors in Tkinter.
348
349\begin{verbatim}
350 button .fred =====> fred = Button()
351\end{verbatim}
352
353The master of an object is implicit in the new name given to it at
354creation time. In Tkinter, masters are specified explicitly.
355
356\begin{verbatim}
357 button .panel.fred =====> fred = Button(panel)
358\end{verbatim}
359
360The configuration options in Tk are given in lists of hyphened tags
361followed by values. In Tkinter, options are specified as
362keyword-arguments in the instance constructor, and keyword-args for
363configure calls or as instance indices, in dictionary style, for
Fred Drake666ca802001-11-16 06:02:55 +0000364established instances. See section~\ref{tkinter-setting-options} on
365setting options.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000366
367\begin{verbatim}
368 button .fred -fg red =====> fred = Button(panel, fg = "red")
369 .fred configure -fg red =====> fred["fg"] = red
370 OR ==> fred.config(fg = "red")
371\end{verbatim}
372
373In Tk, to perform an action on a widget, use the widget name as a
374command, and follow it with an action name, possibly with arguments
375(options). In Tkinter, you call methods on the class instance to
376invoke actions on the widget. The actions (methods) that a given
377widget can perform are listed in the Tkinter.py module.
378
379\begin{verbatim}
380 .fred invoke =====> fred.invoke()
381\end{verbatim}
382
383To give a widget to the packer (geometry manager), you call pack with
384optional arguments. In Tkinter, the Pack class holds all this
385functionality, and the various forms of the pack command are
386implemented as methods. All widgets in \refmodule{Tkinter} are
387subclassed from the Packer, and so inherit all the packing
388methods. See the \refmodule{Tix} module documentation for additional
389information on the Form geometry manager.
390
391\begin{verbatim}
392 pack .fred -side left =====> fred.pack(side = "left")
393\end{verbatim}
394
395
396\subsection{How Tk and Tkinter are Related} % Relationship.html
397
Fred Drake666ca802001-11-16 06:02:55 +0000398\note{This was derived from a graphical image; the image will be used
399 more directly in a subsequent version of this document.}
400
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000401From the top down:
402\begin{description}
403\item[\b{Your App Here (Python)}]
404A Python application makes a \refmodule{Tkinter} call.
405
406\item[\b{Tkinter (Python Module)}]
407This call (say, for example, creating a button widget), is
408implemented in the \emph{Tkinter} module, which is written in
409Python. This Python function will parse the commands and the
410arguments and convert them into a form that makes them look as if they
411had come from a Tk script instead of a Python script.
412
413\item[\b{tkinter (C)}]
414These commands and their arguments will be passed to a C function
415in the \emph{tkinter} - note the lowercase - extension module.
416
417\item[\b{Tk Widgets} (C and Tcl)]
418This C function is able to make calls into other C modules,
419including the C functions that make up the Tk library. Tk is
420implemented in C and some Tcl. The Tcl part of the Tk widgets is used
421to bind certain default behaviors to widgets, and is executed once at
422the point where the Python \refmodule{Tkinter} module is
423imported. (The user never sees this stage).
424
425\item[\b{Tk (C)}]
426The Tk part of the Tk Widgets implement the final mapping to ...
427
428\item[\b{Xlib (C)}]
429the Xlib library to draw graphics on the screen.
430\end{description}
431
432
433\subsection{Handy Reference}
434
435\subsubsection{Setting Options
436 \label{tkinter-setting-options}}
437
438Options control things like the color and border width of a widget.
439Options can be set in three ways:
440
441\begin{description}
442\item[At object creation time, using keyword arguments]:
443\begin{verbatim}
444fred = Button(self, fg = "red", bg = "blue")
445\end{verbatim}
446\item[After object creation, treating the option name like a dictionary index]:
447\begin{verbatim}
448fred["fg"] = "red"
449fred["bg"] = "blue"
450\end{verbatim}
451\item[Use the config() method to update multiple attrs subesequent to
452object creation]:
453\begin{verbatim}
454fred.config(fg = "red", bg = "blue")
455\end{verbatim}
456\end{description}
457
458For a complete explanation of a given option and its behavior, see the
459Tk man pages for the widget in question.
460
461Note that the man pages list "STANDARD OPTIONS" and "WIDGET SPECIFIC
462OPTIONS" for each widget. The former is a list of options that are
463common to many widgets, the latter are the options that are
464ideosyncratic to that particular widget. The Standard Options are
465documented on the \manpage{options}{3} man page.
466
467No distinction between standard and widget-specific options is made in
468this document. Some options don't apply to some kinds of widgets.
469Whether a given widget responds to a particular option depends on the
470class of the widget; buttons have a \code{command} option, labels do not.
471
472The options supported by a given widget are listed in that widget's
473man page, or can be queried at runtime by calling the
Fred Drakec6a525e2002-07-08 14:42:22 +0000474\method{config()} method without arguments, or by calling the
475\method{keys()} method on that widget. The return value of these
476calls is a dictionary whose key is the name of the option as a string
477(for example, \code{'relief'}) and whose values are 5-tuples.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000478
Fred Drakec6a525e2002-07-08 14:42:22 +0000479Some options, like \code{bg} are synonyms for common options with long
480names (\code{bg} is shorthand for "background"). Passing the
481\code{config()} method the name of a shorthand option will return a
4822-tuple, not 5-tuple. The 2-tuple passed back will contain the name of
483the synonym and the ``real'' option (such as \code{('bg',
484'background')}).
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000485
486\begin{tableiii}{c|l|l}{textrm}{Index}{Meaning}{Example}
487 \lineiii{0}{option name} {\code{'relief'}}
488 \lineiii{1}{option name for database lookup} {\code{'relief'}}
489 \lineiii{2}{option class for database lookup} {\code{'Relief'}}
490 \lineiii{3}{default value} {\code{'raised'}}
491 \lineiii{4}{current value} {\code{'groove'}}
492\end{tableiii}
493
494
495Example:
496
497\begin{verbatim}
498>>> print fred.config()
499{'relief' : ('relief', 'relief', 'Relief', 'raised', 'groove')}
500\end{verbatim}
501
502Of course, the dictionary printed will include all the options
503available and their values. This is meant only as an example.
504
505
506\subsubsection{The Packer} % Packer.html
507\index{packing (widgets)}
508
509The packer is one of Tk's geometry-management mechanisms. See also
510\citetitle[classes/ClassPacker.html]{the Packer class interface}.
511
512Geometry managers are used to specify the relative positioning of the
513positioning of widgets within their container - their mutual
514\emph{master}. In contrast to the more cumbersome \emph{placer}
515(which is used less commonly, and we do not cover here), the packer
516takes qualitative relationship specification - \emph{above}, \emph{to
517the left of}, \emph{filling}, etc - and works everything out to
518determine the exact placement coordinates for you.
519
520The size of any \emph{master} widget is determined by the size of
521the "slave widgets" inside. The packer is used to control where slave
522widgets appear inside the master into which they are packed. You can
523pack widgets into frames, and frames into other frames, in order to
524achieve the kind of layout you desire. Additionally, the arrangement
525is dynamically adjusted to accomodate incremental changes to the
526configuration, once it is packed.
527
528Note that widgets do not appear until they have had their geometry
529specified with a geometry manager. It's a common early mistake to
530leave out the geometry specification, and then be surprised when the
531widget is created but nothing appears. A widget will appear only
532after it has had, for example, the packer's \method{pack()} method
533applied to it.
534
535The pack() method can be called with keyword-option/value pairs that
536control where the widget is to appear within its container, and how it
537is to behave when the main application window is resized. Here are
538some examples:
539
540\begin{verbatim}
541 fred.pack() # defaults to side = "top"
542 fred.pack(side = "left")
543 fred.pack(expand = 1)
544\end{verbatim}
545
546
547\subsubsection{Packer Options}
548
549For more extensive information on the packer and the options that it
550can take, see the man pages and page 183 of John Ousterhout's book.
551
552\begin{description}
553\item[\b{anchor }]
554Anchor type. Denotes where the packer is to place each slave in its
555parcel.
556
557\item[\b{expand}]
558Boolean, \code{0} or \code{1}.
559
560\item[\b{fill}]
561Legal values: \code{'x'}, \code{'y'}, \code{'both'}, \code{'none'}.
562
563\item[\b{ipadx} and \b{ipady}]
564A distance - designating internal padding on each side of the slave
565widget.
566
567\item[\b{padx} and \b{pady}]
568A distance - designating external padding on each side of the slave
569widget.
570
571\item[\b{side}]
572Legal values are: \code{'left'}, \code{'right'}, \code{'top'},
573\code{'bottom'}.
574\end{description}
575
576
577\subsubsection{Coupling Widget Variables} % VarCouplings.html
578
579The current-value setting of some widgets (like text entry widgets)
580can be connected directly to application variables by using special
581options. These options are \code{variable}, \code{textvariable},
582\code{onvalue}, \code{offvalue}, and \code{value}. This
583connection works both ways: if the variable changes for any reason,
584the widget it's connected to will be updated to reflect the new value.
585
586Unfortunately, in the current implementation of \refmodule{Tkinter} it is
587not possible to hand over an arbitrary Python variable to a widget
588through a \code{variable} or \code{textvariable} option. The only
589kinds of variables for which this works are variables that are
590subclassed from a class called Variable, defined in the
591\refmodule{Tkinter} module.
592
593There are many useful subclasses of Variable already defined:
594\class{StringVar}, \class{IntVar}, \class{DoubleVar}, and
595\class{BooleanVar}. To read the current value of such a variable,
596call the \method{get()} method on
597it, and to change its value you call the \method{set()} method. If
598you follow this protocol, the widget will always track the value of
599the variable, with no further intervention on your part.
600
601For example:
602\begin{verbatim}
603class App(Frame):
604 def __init__(self, master=None):
605 Frame.__init__(self, master)
606 self.pack()
607
608 self.entrythingy = Entry()
609 self.entrythingy.pack()
610
611 self.button.pack()
612 # here is the application variable
613 self.contents = StringVar()
614 # set it to some value
615 self.contents.set("this is a variable")
616 # tell the entry widget to watch this variable
617 self.entrythingy["textvariable"] = self.contents
618
619 # and here we get a callback when the user hits return.
620 # we will have the program print out the value of the
621 # application variable when the user hits return
622 self.entrythingy.bind('<Key-Return>',
623 self.print_contents)
624
625 def print_contents(self, event):
626 print "hi. contents of entry is now ---->", \
627 self.contents.get()
628\end{verbatim}
629
630
631\subsubsection{The Window Manager} % WindowMgr.html
632\index{window manager (widgets)}
633
634In Tk, there is a utility command, \code{wm}, for interacting with the
635window manager. Options to the \code{wm} command allow you to control
636things like titles, placement, icon bitmaps, and the like. In
637\refmodule{Tkinter}, these commands have been implemented as methods
638on the \class{Wm} class. Toplevel widgets are subclassed from the
639\class{Wm} class, and so can call the \class{Wm} methods directly.
640
641%See also \citetitle[classes/ClassWm.html]{the Wm class interface}.
642
643To get at the toplevel window that contains a given widget, you can
644often just refer to the widget's master. Of course if the widget has
645been packed inside of a frame, the master won't represent a toplevel
646window. To get at the toplevel window that contains an arbitrary
647widget, you can call the \method{_root()} method. This
648method begins with an underscore to denote the fact that this function
649is part of the implementation, and not an interface to Tk functionality.
650
651Here are some examples of typical usage:
652
653\begin{verbatim}
654import Tkinter
655class App(Frame):
656 def __init__(self, master=None):
657 Frame.__init__(self, master)
658 self.pack()
659
660
661# create the application
662myapp = App()
663
664#
665# here are method calls to the window manager class
666#
667myapp.master.title("My Do-Nothing Application")
668myapp.master.maxsize(1000, 400)
669
670# start the program
671myapp.mainloop()
672\end{verbatim}
673
674
675\subsubsection{Tk Option Data Types} % OptionTypes.html
676
677\index{Tk Option Data Types}
678
679\begin{description}
680\item[anchor]
681Legal values are points of the compass: \code{"n"},
682\code{"ne"}, \code{"e"}, \code{"se"}, \code{"s"},
683\code{"sw"}, \code{"w"}, \code{"nw"}, and also
684\code{"center"}.
685
686\item[bitmap]
687There are eight built-in, named bitmaps: \code{'error'}, \code{'gray25'},
688\code{'gray50'}, \code{'hourglass'}, \code{'info'}, \code{'questhead'},
689\code{'question'}, \code{'warning'}. To specify an X bitmap
690filename, give the full path to the file, preceded with an \code{@},
691as in \code{"@/usr/contrib/bitmap/gumby.bit"}.
692
693\item[boolean]
Neal Norwitzcf57e502002-11-03 13:13:20 +0000694You can pass integers 0 or 1 or the strings \code{"yes"} or \code{"no"} .
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000695
696\item[callback]
697This is any Python function that takes no arguments. For example:
698\begin{verbatim}
699 def print_it():
700 print "hi there"
701 fred["command"] = print_it
702\end{verbatim}
703
704\item[color]
705Colors can be given as the names of X colors in the rgb.txt file,
706or as strings representing RGB values in 4 bit: \code{"\#RGB"}, 8
707bit: \code{"\#RRGGBB"}, 12 bit" \code{"\#RRRGGGBBB"}, or 16 bit
708\code{"\#RRRRGGGGBBBB"} ranges, where R,G,B here represent any
709legal hex digit. See page 160 of Ousterhout's book for details.
710
711\item[cursor]
712The standard X cursor names from \file{cursorfont.h} can be used,
713without the \code{XC_} prefix. For example to get a hand cursor
714(\constant{XC_hand2}), use the string \code{"hand2"}. You can also
715specify a bitmap and mask file of your own. See page 179 of
716Ousterhout's book.
717
718\item[distance]
719Screen distances can be specified in either pixels or absolute
720distances. Pixels are given as numbers and absolute distances as
721strings, with the trailing character denoting units: \code{c}
722for centimeters, \code{i} for inches, \code{m} for millimeters,
723\code{p} for printer's points. For example, 3.5 inches is expressed
724as \code{"3.5i"}.
725
726\item[font]
727Tk uses a list font name format, such as \code{\{courier 10 bold\}}.
728Font sizes with positive numbers are measured in points;
729sizes with negative numbers are measured in pixels.
730
731\item[geometry]
732This is a string of the form \samp{\var{width}x\var{height}}, where
733width and height are measured in pixels for most widgets (in
734characters for widgets displaying text). For example:
735\code{fred["geometry"] = "200x100"}.
736
737\item[justify]
738Legal values are the strings: \code{"left"},
739\code{"center"}, \code{"right"}, and \code{"fill"}.
740
741\item[region]
742This is a string with four space-delimited elements, each of
743which is a legal distance (see above). For example: \code{"2 3 4
7445"} and \code{"3i 2i 4.5i 2i"} and \code{"3c 2c 4c 10.43c"}
745are all legal regions.
746
747\item[relief]
748Determines what the border style of a widget will be. Legal
749values are: \code{"raised"}, \code{"sunken"},
750\code{"flat"}, \code{"groove"}, and \code{"ridge"}.
751
752\item[scrollcommand]
753This is almost always the \method{set()} method of some scrollbar
754widget, but can be any widget method that takes a single argument.
755Refer to the file \file{Demo/tkinter/matt/canvas-with-scrollbars.py}
756in the Python source distribution for an example.
757
758\item[wrap:]
759Must be one of: \code{"none"}, \code{"char"}, or \code{"word"}.
760\end{description}
761
762
763\subsubsection{Bindings and Events} % Bindings.html
764
765\index{bind (widgets)}
766\index{events (widgets)}
767
768The bind method from the widget command allows you to watch for
769certain events and to have a callback function trigger when that event
770type occurs. The form of the bind method is:
771
772\begin{verbatim}
773 def bind(self, sequence, func, add=''):
774\end{verbatim}
775where:
776
777\begin{description}
778\item[sequence]
779is a string that denotes the target kind of event. (See the bind
780man page and page 201 of John Ousterhout's book for details).
781
782\item[func]
783is a Python function, taking one argument, to be invoked when the
784event occurs. An Event instance will be passed as the argument.
785(Functions deployed this way are commonly known as \var{callbacks}.)
786
787\item[add]
788is optional, either \samp{} or \samp{+}. Passing an empty string
789denotes that this binding is to replace any other bindings that this
790event is associated with. Preceeding with a \samp{+} means that this
791function is to be added to the list of functions bound to this event type.
792\end{description}
793
794For example:
795\begin{verbatim}
796 def turnRed(self, event):
797 event.widget["activeforeground"] = "red"
798
799 self.button.bind("<Enter>", self.turnRed)
800\end{verbatim}
801
802Notice how the widget field of the event is being accesed in the
803\method{turnRed()} callback. This field contains the widget that
804caught the X event. The following table lists the other event fields
805you can access, and how they are denoted in Tk, which can be useful
806when referring to the Tk man pages.
807
808\begin{verbatim}
809Tk Tkinter Event Field Tk Tkinter Event Field
810-- ------------------- -- -------------------
811%f focus %A char
812%h height %E send_event
813%k keycode %K keysym
814%s state %N keysym_num
815%t time %T type
816%w width %W widget
817%x x %X x_root
818%y y %Y y_root
819\end{verbatim}
820
821
822\subsubsection{The index Parameter} % Index.html
823
824A number of widgets require``index'' parameters to be passed. These
825are used to point at a specific place in a Text widget, or to
826particular characters in an Entry widget, or to particular menu items
827in a Menu widget.
828
829\begin{description}
830\item[\b{Entry widget indexes (index, view index, etc.)}]
831Entry widgets have options that refer to character positions in the
832text being displayed. You can use these \refmodule{Tkinter} functions
833to access these special points in text widgets:
Fred Drake666ca802001-11-16 06:02:55 +0000834
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000835\begin{description}
836\item[AtEnd()]
837refers to the last position in the text
Fred Drake666ca802001-11-16 06:02:55 +0000838
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000839\item[AtInsert()]
840refers to the point where the text cursor is
Fred Drake666ca802001-11-16 06:02:55 +0000841
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000842\item[AtSelFirst()]
843indicates the beginning point of the selected text
Fred Drake666ca802001-11-16 06:02:55 +0000844
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000845\item[AtSelLast()]
846denotes the last point of the selected text and finally
Fred Drake666ca802001-11-16 06:02:55 +0000847
848\item[At(x\optional{, y})]
849refers to the character at pixel location \var{x}, \var{y} (with
850\var{y} not used in the case of a text entry widget, which contains a
851single line of text).
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000852\end{description}
853
854\item[\b{Text widget indexes}]
855The index notation for Text widgets is very rich and is best described
856in the Tk man pages.
857
858\item[\b{Menu indexes (menu.invoke(), menu.entryconfig(), etc.)}]
859
860Some options and methods for menus manipulate specific menu entries.
861Anytime a menu index is needed for an option or a parameter, you may
862pass in:
863\begin{itemize}
864\item an integer which refers to the numeric position of the entry in
865the widget, counted from the top, starting with 0;
866\item the string \code{'active'}, which refers to the menu position that is
867currently under the cursor;
868\item the string \code{"last"} which refers to the last menu
869item;
870\item An integer preceded by \code{@}, as in \code{@6}, where the integer is
871interpreted as a y pixel coordinate in the menu's coordinate system;
872\item the string \code{"none"}, which indicates no menu entry at all, most
873often used with menu.activate() to deactivate all entries, and
874finally,
875\item a text string that is pattern matched against the label of the
876menu entry, as scanned from the top of the menu to the bottom. Note
877that this index type is considered after all the others, which means
878that matches for menu items labelled \code{last}, \code{active}, or
879\code{none} may be interpreted as the above literals, instead.
880\end{itemize}
881\end{description}
882
Martin v. Löwisa288a232002-11-05 22:11:50 +0000883\subsubsection{Images}
884
885Bitmap/Pixelmap images can be created through the subclasses of
886\class{Tkinter.Image}:
887
888\begin{itemize}
889\item \class{BitmapImage} can be used for X11 bitmap data.
890\item \class{PhotoImage} can be used for GIF and PPM/PGM color bitmaps.
891\end{itemize}
892
893Either type of image is created through either the \code{file} or the
894\code{data} option (other options are available as well).
895
Neal Norwitzfad265e2002-11-05 22:46:39 +0000896The image object can then be used wherever an \code{image} option is
Martin v. Löwisa288a232002-11-05 22:11:50 +0000897supported by some widget (e.g. labels, buttons, menus). In these
898cases, Tk will not keep a reference to the image. When the last Python
899reference to the image object is deleted, the image data is deleted as
Neal Norwitzfad265e2002-11-05 22:46:39 +0000900well, and Tk will display an empty box wherever the image was used.
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000901
Fred Drakec66ff202001-11-16 01:05:27 +0000902\section{\module{Tix} ---
903 Extension widgets for Tk}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000904
905\declaremodule{standard}{Tix}
906\modulesynopsis{Tk Extension Widgets for Tkinter}
907\sectionauthor{Mike Clarkson}{mikeclarkson@users.sourceforge.net}
908
Fred Drakec66ff202001-11-16 01:05:27 +0000909\index{Tix}
910
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000911The \module{Tix} (Tk Interface Extension) module provides an
912additional rich set of widgets. Although the standard Tk library has
913many useful widgets, they are far from complete. The \module{Tix}
914library provides most of the commonly needed widgets that are missing
915from standard Tk: \class{HList}, \class{ComboBox}, \class{Control}
916(a.k.a. SpinBox) and an assortment of scrollable widgets. \module{Tix}
917also includes many more widgets that are generally useful in a wide
918range of applications: \class{NoteBook}, \class{FileEntry},
919\class{PanedWindow}, etc; there are more than 40 of them.
920
921With all these new widgets, you can introduce new interaction
922techniques into applications, creating more useful and more intuitive
923user interfaces. You can design your application by choosing the most
924appropriate widgets to match the special needs of your application and
925users.
926
927\begin{seealso}
928\seetitle[http://tix.sourceforge.net/]
929 {Tix Homepage}
Fred Drakea0b76762001-12-13 04:25:37 +0000930 {The home page for \module{Tix}. This includes links to
931 additional documentation and downloads.}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000932\seetitle[http://tix.sourceforge.net/dist/current/man/]
933 {Tix Man Pages}
934 {On-line version of the man pages and reference material.}
935\seetitle[http://tix.sourceforge.net/dist/current/docs/tix-book/tix.book.html]
936 {Tix Programming Guide}
937 {On-line version of the programmer's reference material.}
938\seetitle[http://tix.sourceforge.net/Tide/]
939 {Tix Development Applications}
940 {Tix applications for development of Tix and Tkinter programs.
941 Tide applications work under Tk or Tkinter, and include
942 \program{TixInspect}, an inspector to remotely modify and
943 debug Tix/Tk/Tkinter applications.}
944\end{seealso}
945
946
947\subsection{Using Tix}
948
Fred Drake666ca802001-11-16 06:02:55 +0000949\begin{classdesc}{Tix}{screenName\optional{, baseName\optional{, className}}}
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000950 Toplevel widget of Tix which represents mostly the main window
951 of an application. It has an associated Tcl interpreter.
952
Fred Drake666ca802001-11-16 06:02:55 +0000953Classes in the \refmodule{Tix} module subclasses the classes in the
954\refmodule{Tkinter} module. The former imports the latter, so to use
955\refmodule{Tix} with Tkinter, all you need to do is to import one
956module. In general, you can just import \refmodule{Tix}, and replace
957the toplevel call to \class{Tkinter.Tk} with \class{Tix.Tk}:
Fred Drake7cf4e5b2001-11-15 17:22:04 +0000958\begin{verbatim}
959import Tix
960from Tkconstants import *
961root = Tix.Tk()
962\end{verbatim}
963\end{classdesc}
964
965To use \refmodule{Tix}, you must have the \refmodule{Tix} widgets installed,
966usually alongside your installation of the Tk widgets.
967To test your installation, try the following:
968\begin{verbatim}
969import Tix
970root = Tix.Tk()
971root.tk.eval('package require Tix')
972\end{verbatim}
973
974If this fails, you have a Tk installation problem which must be
975resolved before proceeding. Use the environment variable \envvar{TIX_LIBRARY}
976to point to the installed \refmodule{Tix} library directory, and
977make sure you have the dynamic object library (\file{tix8183.dll} or
978\file{libtix8183.so}) in the same directory that contains your Tk
979dynamic object library (\file{tk8183.dll} or \file{libtk8183.so}). The
980directory with the dynamic object library should also have a file
981called \file{pkgIndex.tcl} (case sensitive), which contains the line:
982
983\begin{verbatim}
984package ifneeded Tix 8.1 [list load "[file join $dir tix8183.dll]" Tix]
985\end{verbatim} % $ <-- bow to font-lock
986
987
988\subsection{Tix Widgets}
989
990\ulink{Tix}
991{http://tix.sourceforge.net/dist/current/man/html/TixCmd/TixIntro.htm}
992introduces over 40 widget classes to the \refmodule{Tkinter}
993repertoire. There is a demo of all the \refmodule{Tix} widgets in the
994\file{Demo/tix} directory of the standard distribution.
995
996
997% The Python sample code is still being added to Python, hence commented out
998
999
1000\subsubsection{Basic Widgets}
1001
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001002\begin{classdesc}{Balloon}{}
1003A \ulink{Balloon}
Fred Drakec66ff202001-11-16 01:05:27 +00001004{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixBalloon.htm}
1005that pops up over a widget to provide help. When the user moves the
1006cursor inside a widget to which a Balloon widget has been bound, a
1007small pop-up window with a descriptive message will be shown on the
1008screen.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001009\end{classdesc}
1010
Fred Drakec66ff202001-11-16 01:05:27 +00001011% Python Demo of:
1012% \ulink{Balloon}{http://tix.sourceforge.net/dist/current/demos/samples/Balloon.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001013
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001014\begin{classdesc}{ButtonBox}{}
1015The \ulink{ButtonBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001016{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixButtonBox.htm}
1017widget creates a box of buttons, such as is commonly used for \code{Ok
1018Cancel}.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001019\end{classdesc}
1020
Fred Drakec66ff202001-11-16 01:05:27 +00001021% Python Demo of:
1022% \ulink{ButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/BtnBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001023
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001024\begin{classdesc}{ComboBox}{}
1025The \ulink{ComboBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001026{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixComboBox.htm}
1027widget is similar to the combo box control in MS Windows. The user can
1028select a choice by either typing in the entry subwdget or selecting
1029from the listbox subwidget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001030\end{classdesc}
1031
Fred Drakec66ff202001-11-16 01:05:27 +00001032% Python Demo of:
1033% \ulink{ComboBox}{http://tix.sourceforge.net/dist/current/demos/samples/ComboBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001034
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001035\begin{classdesc}{Control}{}
1036The \ulink{Control}
Fred Drakec66ff202001-11-16 01:05:27 +00001037{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixControl.htm}
1038widget is also known as the \class{SpinBox} widget. The user can
1039adjust the value by pressing the two arrow buttons or by entering the
1040value directly into the entry. The new value will be checked against
1041the user-defined upper and lower limits.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001042\end{classdesc}
1043
Fred Drakec66ff202001-11-16 01:05:27 +00001044% Python Demo of:
1045% \ulink{Control}{http://tix.sourceforge.net/dist/current/demos/samples/Control.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001046
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001047\begin{classdesc}{LabelEntry}{}
1048The \ulink{LabelEntry}
Fred Drakec66ff202001-11-16 01:05:27 +00001049{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelEntry.htm}
1050widget packages an entry widget and a label into one mega widget. It
1051can be used be used to simplify the creation of ``entry-form'' type of
1052interface.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001053\end{classdesc}
1054
1055% Python Demo of:
1056% \ulink{LabelEntry}{http://tix.sourceforge.net/dist/current/demos/samples/LabEntry.tcl}
1057
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001058\begin{classdesc}{LabelFrame}{}
1059The \ulink{LabelFrame}
Fred Drakec66ff202001-11-16 01:05:27 +00001060{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelFrame.htm}
1061widget packages a frame widget and a label into one mega widget. To
1062create widgets inside a LabelFrame widget, one creates the new widgets
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001063relative to the \member{frame} subwidget and manage them inside the
1064\member{frame} subwidget.
1065\end{classdesc}
1066
1067% Python Demo of:
1068% \ulink{LabelFrame}{http://tix.sourceforge.net/dist/current/demos/samples/LabFrame.tcl}
1069
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001070\begin{classdesc}{Meter}{}
1071The \ulink{Meter}
Fred Drakec66ff202001-11-16 01:05:27 +00001072{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixMeter.htm}
1073widget can be used to show the progress of a background job which may
1074take a long time to execute.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001075\end{classdesc}
1076
1077% Python Demo of:
1078% \ulink{Meter}{http://tix.sourceforge.net/dist/current/demos/samples/Meter.tcl}
1079
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001080\begin{classdesc}{OptionMenu}{}
1081The \ulink{OptionMenu}
Fred Drakec66ff202001-11-16 01:05:27 +00001082{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixOptionMenu.htm}
1083creates a menu button of options.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001084\end{classdesc}
1085
Fred Drakec66ff202001-11-16 01:05:27 +00001086% Python Demo of:
1087% \ulink{OptionMenu}{http://tix.sourceforge.net/dist/current/demos/samples/OptMenu.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001088
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001089\begin{classdesc}{PopupMenu}{}
1090The \ulink{PopupMenu}
Fred Drakec66ff202001-11-16 01:05:27 +00001091{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPopupMenu.htm}
1092widget can be used as a replacement of the \code{tk_popup}
1093command. The advantage of the \refmodule{Tix} \class{PopupMenu} widget
1094is it requires less application code to manipulate.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001095\end{classdesc}
1096
Fred Drakec66ff202001-11-16 01:05:27 +00001097% Python Demo of:
1098% \ulink{PopupMenu}{http://tix.sourceforge.net/dist/current/demos/samples/PopMenu.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001099
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001100\begin{classdesc}{Select}{}
1101The \ulink{Select}
Fred Drakec66ff202001-11-16 01:05:27 +00001102{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixSelect.htm}
1103widget is a container of button subwidgets. It can be used to provide
1104radio-box or check-box style of selection options for the user.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001105\end{classdesc}
1106
Fred Drakec66ff202001-11-16 01:05:27 +00001107% Python Demo of:
1108% \ulink{Select}{http://tix.sourceforge.net/dist/current/demos/samples/Select.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001109
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001110\begin{classdesc}{StdButtonBox}{}
1111The \ulink{StdButtonBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001112{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixStdButtonBox.htm}
1113widget is a group of standard buttons for Motif-like dialog boxes.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001114\end{classdesc}
1115
Fred Drakec66ff202001-11-16 01:05:27 +00001116% Python Demo of:
1117% \ulink{StdButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/StdBBox.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001118
1119
1120\subsubsection{File Selectors}
1121
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001122\begin{classdesc}{DirList}{}
1123The \ulink{DirList}
1124{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirList.htm} widget
1125displays a list view of a directory, its previous directories and its
1126sub-directories. The user can choose one of the directories displayed
1127in the list or change to another directory.
1128\end{classdesc}
1129
Fred Drakec66ff202001-11-16 01:05:27 +00001130% Python Demo of:
1131% \ulink{DirList}{http://tix.sourceforge.net/dist/current/demos/samples/DirList.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001132
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001133\begin{classdesc}{DirTree}{}
1134The \ulink{DirTree}
Fred Drakec66ff202001-11-16 01:05:27 +00001135{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirTree.htm}
1136widget displays a tree view of a directory, its previous directories
1137and its sub-directories. The user can choose one of the directories
1138displayed in the list or change to another directory.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001139\end{classdesc}
1140
Fred Drakec66ff202001-11-16 01:05:27 +00001141% Python Demo of:
1142% \ulink{DirTree}{http://tix.sourceforge.net/dist/current/demos/samples/DirTree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001143
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001144\begin{classdesc}{DirSelectDialog}{}
1145The \ulink{DirSelectDialog}
Fred Drakec66ff202001-11-16 01:05:27 +00001146{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirSelectDialog.htm}
1147widget presents the directories in the file system in a dialog
1148window. The user can use this dialog window to navigate through the
1149file system to select the desired directory.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001150\end{classdesc}
1151
Fred Drakec66ff202001-11-16 01:05:27 +00001152% Python Demo of:
1153% \ulink{DirSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/DirDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001154
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001155\begin{classdesc}{DirSelectBox}{}
1156The \class{DirSelectBox} is similar
1157to the standard Motif(TM) directory-selection box. It is generally used for
1158the user to choose a directory. DirSelectBox stores the directories mostly
1159recently selected into a ComboBox widget so that they can be quickly
1160selected again.
1161\end{classdesc}
1162
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001163\begin{classdesc}{ExFileSelectBox}{}
1164The \ulink{ExFileSelectBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001165{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixExFileSelectBox.htm}
1166widget is usually embedded in a tixExFileSelectDialog widget. It
1167provides an convenient method for the user to select files. The style
1168of the \class{ExFileSelectBox} widget is very similar to the standard
1169file dialog on MS Windows 3.1.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001170\end{classdesc}
1171
Fred Drakec66ff202001-11-16 01:05:27 +00001172% Python Demo of:
1173%\ulink{ExFileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/EFileDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001174
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001175\begin{classdesc}{FileSelectBox}{}
1176The \ulink{FileSelectBox}
Fred Drakec66ff202001-11-16 01:05:27 +00001177{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileSelectBox.htm}
1178is similar to the standard Motif(TM) file-selection box. It is
1179generally used for the user to choose a file. FileSelectBox stores the
1180files mostly recently selected into a \class{ComboBox} widget so that
1181they can be quickly selected again.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001182\end{classdesc}
1183
Fred Drakec66ff202001-11-16 01:05:27 +00001184% Python Demo of:
1185% \ulink{FileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/FileDlg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001186
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001187\begin{classdesc}{FileEntry}{}
1188The \ulink{FileEntry}
Fred Drakec66ff202001-11-16 01:05:27 +00001189{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileEntry.htm}
1190widget can be used to input a filename. The user can type in the
1191filename manually. Alternatively, the user can press the button widget
1192that sits next to the entry, which will bring up a file selection
1193dialog.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001194\end{classdesc}
1195
Fred Drakec66ff202001-11-16 01:05:27 +00001196% Python Demo of:
1197% \ulink{FileEntry}{http://tix.sourceforge.net/dist/current/demos/samples/FileEnt.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001198
1199
1200\subsubsection{Hierachical ListBox}
1201
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001202\begin{classdesc}{HList}{}
1203The \ulink{HList}
Fred Drakec66ff202001-11-16 01:05:27 +00001204{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixHList.htm}
1205widget can be used to display any data that have a hierarchical
1206structure, for example, file system directory trees. The list entries
1207are indented and connected by branch lines according to their places
1208in the hierachy.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001209\end{classdesc}
1210
Fred Drakec66ff202001-11-16 01:05:27 +00001211% Python Demo of:
1212% \ulink{HList}{http://tix.sourceforge.net/dist/current/demos/samples/HList1.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001213
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001214\begin{classdesc}{CheckList}{}
1215The \ulink{CheckList}
Fred Drakec66ff202001-11-16 01:05:27 +00001216{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixCheckList.htm}
1217widget displays a list of items to be selected by the user. CheckList
1218acts similarly to the Tk checkbutton or radiobutton widgets, except it
1219is capable of handling many more items than checkbuttons or
1220radiobuttons.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001221\end{classdesc}
1222
Fred Drakec66ff202001-11-16 01:05:27 +00001223% Python Demo of:
1224% \ulink{ CheckList}{http://tix.sourceforge.net/dist/current/demos/samples/ChkList.tcl}
1225% Python Demo of:
1226% \ulink{ScrolledHList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList.tcl}
1227% Python Demo of:
1228% \ulink{ScrolledHList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001229
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001230\begin{classdesc}{Tree}{}
1231The \ulink{Tree}
Fred Drakec66ff202001-11-16 01:05:27 +00001232{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTree.htm}
1233widget can be used to display hierachical data in a tree form. The
1234user can adjust the view of the tree by opening or closing parts of
1235the tree.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001236\end{classdesc}
1237
Fred Drakec66ff202001-11-16 01:05:27 +00001238% Python Demo of:
1239% \ulink{Tree}{http://tix.sourceforge.net/dist/current/demos/samples/Tree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001240
Fred Drakec66ff202001-11-16 01:05:27 +00001241% Python Demo of:
1242% \ulink{Tree (Dynamic)}{http://tix.sourceforge.net/dist/current/demos/samples/DynTree.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001243
1244
1245\subsubsection{Tabular ListBox}
1246
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001247\begin{classdesc}{TList}{}
1248The \ulink{TList}
Fred Drakec66ff202001-11-16 01:05:27 +00001249{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTList.htm}
1250widget can be used to display data in a tabular format. The list
1251entries of a \class{TList} widget are similar to the entries in the Tk
1252listbox widget. The main differences are (1) the \class{TList} widget
1253can display the list entries in a two dimensional format and (2) you
1254can use graphical images as well as multiple colors and fonts for the
1255list entries.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001256\end{classdesc}
1257
Fred Drakec66ff202001-11-16 01:05:27 +00001258% Python Demo of:
1259% \ulink{ScrolledTList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/STList1.tcl}
1260% Python Demo of:
1261% \ulink{ScrolledTList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/STList2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001262
1263% Grid has yet to be added to Python
1264% \subsubsection{Grid Widget}
Fred Drakec66ff202001-11-16 01:05:27 +00001265% Python Demo of:
1266% \ulink{Simple Grid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid0.tcl}
1267% Python Demo of:
1268% \ulink{ScrolledGrid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid1.tcl}
1269% Python Demo of:
1270% \ulink{Editable Grid}{http://tix.sourceforge.net/dist/current/demos/samples/EditGrid.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001271
1272
1273\subsubsection{Manager Widgets}
1274
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001275\begin{classdesc}{PanedWindow}{}
1276The \ulink{PanedWindow}
Fred Drakec66ff202001-11-16 01:05:27 +00001277{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPanedWindow.htm}
1278widget allows the user to interactively manipulate the sizes of
1279several panes. The panes can be arranged either vertically or
1280horizontally. The user changes the sizes of the panes by dragging the
1281resize handle between two panes.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001282\end{classdesc}
1283
Fred Drakec66ff202001-11-16 01:05:27 +00001284% Python Demo of:
1285% \ulink{PanedWindow}{http://tix.sourceforge.net/dist/current/demos/samples/PanedWin.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001286
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001287\begin{classdesc}{ListNoteBook}{}
1288The \ulink{ListNoteBook}
Fred Drakec66ff202001-11-16 01:05:27 +00001289{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixListNoteBook.htm}
1290widget is very similar to the \class{TixNoteBook} widget: it can be
1291used to display many windows in a limited space using a notebook
1292metaphor. The notebook is divided into a stack of pages (windows). At
1293one time only one of these pages can be shown. The user can navigate
1294through these pages by choosing the name of the desired page in the
1295\member{hlist} subwidget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001296\end{classdesc}
1297
Fred Drakec66ff202001-11-16 01:05:27 +00001298% Python Demo of:
1299% \ulink{ListNoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/ListNBK.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001300
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001301\begin{classdesc}{NoteBook}{}
1302The \ulink{NoteBook}
Fred Drakec66ff202001-11-16 01:05:27 +00001303{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixNoteBook.htm}
1304widget can be used to display many windows in a limited space using a
1305notebook metaphor. The notebook is divided into a stack of pages. At
1306one time only one of these pages can be shown. The user can navigate
1307through these pages by choosing the visual ``tabs'' at the top of the
1308NoteBook widget.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001309\end{classdesc}
1310
Fred Drakec66ff202001-11-16 01:05:27 +00001311% Python Demo of:
1312% \ulink{NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/NoteBook.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001313
1314
1315% \subsubsection{Scrolled Widgets}
Fred Drakec66ff202001-11-16 01:05:27 +00001316% Python Demo of:
1317% \ulink{ScrolledListBox}{http://tix.sourceforge.net/dist/current/demos/samples/SListBox.tcl}
1318% Python Demo of:
1319% \ulink{ScrolledText}{http://tix.sourceforge.net/dist/current/demos/samples/SText.tcl}
1320% Python Demo of:
1321% \ulink{ScrolledWindow}{http://tix.sourceforge.net/dist/current/demos/samples/SWindow.tcl}
1322% Python Demo of:
1323% \ulink{Canvas Object View}{http://tix.sourceforge.net/dist/current/demos/samples/CObjView.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001324
1325
1326\subsubsection{Image Types}
1327
1328The \refmodule{Tix} module adds:
1329\begin{itemize}
1330\item
1331\ulink{pixmap}
Fred Drake666ca802001-11-16 06:02:55 +00001332{http://tix.sourceforge.net/dist/current/man/html/TixCmd/pixmap.htm}
1333capabilities to all \refmodule{Tix} and \refmodule{Tkinter} widgets to
1334create color images from XPM files.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001335
Fred Drakea0b76762001-12-13 04:25:37 +00001336% Python Demo of:
1337% \ulink{XPM Image In Button}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001338
Fred Drakea0b76762001-12-13 04:25:37 +00001339% Python Demo of:
1340% \ulink{XPM Image In Menu}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm1.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001341
1342\item
1343\ulink{Compound}
Fred Drake666ca802001-11-16 06:02:55 +00001344{http://tix.sourceforge.net/dist/current/man/html/TixCmd/compound.html}
1345image types can be used to create images that consists of multiple
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001346horizontal lines; each line is composed of a series of items (texts,
1347bitmaps, images or spaces) arranged from left to right. For example, a
1348compound image can be used to display a bitmap and a text string
1349simutaneously in a Tk \class{Button} widget.
1350
Fred Drake666ca802001-11-16 06:02:55 +00001351% Python Demo of:
1352% \ulink{Compound Image In Buttons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001353
Fred Drake666ca802001-11-16 06:02:55 +00001354% Python Demo of:
1355% \ulink{Compound Image In NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg2.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001356
Fred Drake666ca802001-11-16 06:02:55 +00001357% Python Demo of:
1358% \ulink{Compound Image Notebook Color Tabs}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg4.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001359
Fred Drake666ca802001-11-16 06:02:55 +00001360% Python Demo of:
1361% \ulink{Compound Image Icons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg3.tcl}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001362\end{itemize}
1363
1364
1365\subsubsection{Miscellaneous Widgets}
1366
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001367\begin{classdesc}{InputOnly}{}
1368The \ulink{InputOnly}
Fred Drake666ca802001-11-16 06:02:55 +00001369{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixInputOnly.htm}
1370widgets are to accept inputs from the user, which can be done with the
1371\code{bind} command (\UNIX{} only).
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001372\end{classdesc}
1373
1374\subsubsection{Form Geometry Manager}
1375
1376In addition, \refmodule{Tix} augments \refmodule{Tkinter} by providing:
Fred Drake666ca802001-11-16 06:02:55 +00001377
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001378\begin{classdesc}{Form}{}
1379The \ulink{Form}
Fred Drake666ca802001-11-16 06:02:55 +00001380{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixForm.htm}
1381geometry manager based on attachment rules for all Tk widgets.
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001382\end{classdesc}
1383
1384
1385%begin{latexonly}
1386%\subsection{Tix Class Structure}
1387%
1388%\begin{figure}[hbtp]
1389%\centerline{\epsfig{file=hierarchy.png,width=.9\textwidth}}
1390%\vspace{.5cm}
1391%\caption{The Class Hierarchy of Tix Widgets}
1392%\end{figure}
1393%end{latexonly}
1394
Fred Drake44b6f842001-11-29 21:09:08 +00001395\subsection{Tix Commands}
1396
1397\begin{classdesc}{tixCommand}{}
1398The \ulink{tix commands}
1399{http://tix.sourceforge.net/dist/current/man/html/TixCmd/tix.htm}
1400provide access to miscellaneous elements of \refmodule{Tix}'s internal
1401state and the \refmodule{Tix} application context. Most of the information
1402manipulated by these methods pertains to the application as a whole,
1403or to a screen or display, rather than to a particular window.
1404
1405To view the current settings, the common usage is:
1406\begin{verbatim}
1407import Tix
1408root = Tix.Tk()
1409print root.tix_configure()
1410\end{verbatim}
1411\end{classdesc}
1412
1413\begin{methoddesc}{tix_configure}{\optional{cnf,} **kw}
1414Query or modify the configuration options of the Tix application
1415context. If no option is specified, returns a dictionary all of the
1416available options. If option is specified with no value, then the
1417method returns a list describing the one named option (this list will
1418be identical to the corresponding sublist of the value returned if no
1419option is specified). If one or more option-value pairs are
1420specified, then the method modifies the given option(s) to have the
1421given value(s); in this case the method returns an empty string.
1422Option may be any of the configuration options.
1423\end{methoddesc}
1424
1425\begin{methoddesc}{tix_cget}{option}
1426Returns the current value of the configuration option given by
1427\var{option}. Option may be any of the configuration options.
1428\end{methoddesc}
1429
1430\begin{methoddesc}{tix_getbitmap}{name}
1431Locates a bitmap file of the name \code{name.xpm} or \code{name} in
1432one of the bitmap directories (see the \method{tix_addbitmapdir()}
1433method). By using \method{tix_getbitmap()}, you can avoid hard
1434coding the pathnames of the bitmap files in your application. When
1435successful, it returns the complete pathname of the bitmap file,
1436prefixed with the character \samp{@}. The returned value can be used to
1437configure the \code{bitmap} option of the Tk and Tix widgets.
1438\end{methoddesc}
1439
1440\begin{methoddesc}{tix_addbitmapdir}{directory}
1441Tix maintains a list of directories under which the
1442\method{tix_getimage()} and \method{tix_getbitmap()} methods will
1443search for image files. The standard bitmap directory is
1444\file{\$TIX_LIBRARY/bitmaps}. The \method{tix_addbitmapdir()} method
1445adds \var{directory} into this list. By using this method, the image
1446files of an applications can also be located using the
1447\method{tix_getimage()} or \method{tix_getbitmap()} method.
1448\end{methoddesc}
1449
1450\begin{methoddesc}{tix_filedialog}{\optional{dlgclass}}
1451Returns the file selection dialog that may be shared among different
1452calls from this application. This method will create a file selection
1453dialog widget when it is called the first time. This dialog will be
1454returned by all subsequent calls to \method{tix_filedialog()}. An
1455optional dlgclass parameter can be passed as a string to specified
1456what type of file selection dialog widget is desired. Possible
1457options are \code{tix}, \code{FileSelectDialog} or
1458\code{tixExFileSelectDialog}.
1459\end{methoddesc}
1460
1461
1462\begin{methoddesc}{tix_getimage}{self, name}
1463Locates an image file of the name \file{name.xpm}, \file{name.xbm} or
1464\file{name.ppm} in one of the bitmap directories (see the
1465\method{tix_addbitmapdir()} method above). If more than one file with
1466the same name (but different extensions) exist, then the image type is
1467chosen according to the depth of the X display: xbm images are chosen
1468on monochrome displays and color images are chosen on color
1469displays. By using \method{tix_getimage()}, you can avoid hard coding
1470the pathnames of the image files in your application. When successful,
1471this method returns the name of the newly created image, which can be
1472used to configure the \code{image} option of the Tk and Tix widgets.
1473\end{methoddesc}
1474
1475\begin{methoddesc}{tix_option_get}{name}
1476Gets the options manitained by the Tix scheme mechanism.
1477\end{methoddesc}
1478
1479\begin{methoddesc}{tix_resetoptions}{newScheme, newFontSet\optional{,
1480 newScmPrio}}
1481Resets the scheme and fontset of the Tix application to
1482\var{newScheme} and \var{newFontSet}, respectively. This affects only
1483those widgets created after this call. Therefore, it is best to call
1484the resetoptions method before the creation of any widgets in a Tix
1485application.
1486
1487The optional parameter \var{newScmPrio} can be given to reset the
1488priority level of the Tk options set by the Tix schemes.
1489
1490Because of the way Tk handles the X option database, after Tix has
1491been has imported and inited, it is not possible to reset the color
1492schemes and font sets using the \method{tix_config()} method.
1493Instead, the \method{tix_resetoptions()} method must be used.
1494\end{methoddesc}
1495
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001496
Fred Drake1a763862001-12-03 21:18:30 +00001497
1498\section{\module{ScrolledText} ---
1499 Scrolled Text Widget}
1500
1501\declaremodule{standard}{ScrolledText}
1502 \platform{Tk}
1503\modulesynopsis{Text widget with a vertical scroll bar.}
1504\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
1505
1506The \module{ScrolledText} module provides a class of the same name
1507which implements a basic text widget which has a vertical scroll bar
1508configured to do the ``right thing.'' Using the \class{ScrolledText}
1509class is a lot easier than setting up a text widget and scroll bar
1510directly. The constructor is the same as that of the
1511\class{Tkinter.Text} class.
1512
1513The text widget and scrollbar are packed together in a \class{Frame},
Fred Drakea0b76762001-12-13 04:25:37 +00001514and the methods of the \class{Grid} and \class{Pack} geometry managers
1515are acquired from the \class{Frame} object. This allows the
1516\class{ScrolledText} widget to be used directly to achieve most normal
1517geometry management behavior.
Fred Drake1a763862001-12-03 21:18:30 +00001518
1519Should more specific control be necessary, the following attributes
1520are available:
1521
1522\begin{memberdesc}[ScrolledText]{frame}
1523 The frame which surrounds the text and scroll bar widgets.
1524\end{memberdesc}
1525
1526\begin{memberdesc}[ScrolledText]{vbar}
1527 The scroll bar widget.
1528\end{memberdesc}
1529
1530
Fred Drakec66ff202001-11-16 01:05:27 +00001531\input{libturtle}
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001532
1533
1534\section{Idle \label{idle}}
1535
1536%\declaremodule{standard}{idle}
1537%\modulesynopsis{A Python Integrated Developement Environment}
1538\moduleauthor{Guido van Rossum}{guido@Python.org}
1539
1540Idle is the Python IDE built with the \refmodule{Tkinter} GUI toolkit.
1541\index{Idle}
1542\index{Python Editor}
1543\index{Integrated Developement Environment}
1544
1545
1546IDLE has the following features:
1547
1548\begin{itemize}
1549\item coded in 100\% pure Python, using the \refmodule{Tkinter} GUI toolkit
1550
1551\item cross-platform: works on Windows and \UNIX{} (on Mac OS, there are
1552currently problems with Tcl/Tk)
1553
1554\item multi-window text editor with multiple undo, Python colorizing
1555and many other features, e.g. smart indent and call tips
1556
1557\item Python shell window (a.k.a. interactive interpreter)
1558
1559\item debugger (not complete, but you can set breakpoints, view and step)
1560\end{itemize}
1561
1562
1563\subsection{Menus}
1564
1565\subsubsection{File menu}
1566
1567\begin{description}
1568\item[New window] create a new editing window
1569\item[Open...] open an existing file
1570\item[Open module...] open an existing module (searches sys.path)
1571\item[Class browser] show classes and methods in current file
1572\item[Path browser] show sys.path directories, modules, classes and methods
1573\end{description}
1574\index{Class browser}
1575\index{Path browser}
1576
1577\begin{description}
1578\item[Save] save current window to the associated file (unsaved
1579windows have a * before and after the window title)
1580
1581\item[Save As...] save current window to new file, which becomes
1582the associated file
1583\item[Save Copy As...] save current window to different file
1584without changing the associated file
1585\end{description}
1586
1587\begin{description}
1588\item[Close] close current window (asks to save if unsaved)
1589\item[Exit] close all windows and quit IDLE (asks to save if unsaved)
1590\end{description}
1591
1592
1593\subsubsection{Edit menu}
1594
1595\begin{description}
1596\item[Undo] Undo last change to current window (max 1000 changes)
1597\item[Redo] Redo last undone change to current window
1598\end{description}
1599
1600\begin{description}
1601\item[Cut] Copy selection into system-wide clipboard; then delete selection
1602\item[Copy] Copy selection into system-wide clipboard
1603\item[Paste] Insert system-wide clipboard into window
1604\item[Select All] Select the entire contents of the edit buffer
1605\end{description}
1606
1607\begin{description}
1608\item[Find...] Open a search dialog box with many options
1609\item[Find again] Repeat last search
1610\item[Find selection] Search for the string in the selection
1611\item[Find in Files...] Open a search dialog box for searching files
1612\item[Replace...] Open a search-and-replace dialog box
1613\item[Go to line] Ask for a line number and show that line
1614\end{description}
1615
1616\begin{description}
1617\item[Indent region] Shift selected lines right 4 spaces
1618\item[Dedent region] Shift selected lines left 4 spaces
1619\item[Comment out region] Insert \#\# in front of selected lines
1620\item[Uncomment region] Remove leading \# or \#\# from selected lines
1621\item[Tabify region] Turns \emph{leading} stretches of spaces into tabs
1622\item[Untabify region] Turn \emph{all} tabs into the right number of spaces
1623\item[Expand word] Expand the word you have typed to match another
1624 word in the same buffer; repeat to get a different expansion
1625\item[Format Paragraph] Reformat the current blank-line-separated paragraph
1626\end{description}
1627
1628\begin{description}
1629\item[Import module] Import or reload the current module
1630\item[Run script] Execute the current file in the __main__ namespace
1631\end{description}
1632
1633\index{Import module}
1634\index{Run script}
1635
1636
1637\subsubsection{Windows menu}
1638
1639\begin{description}
1640\item[Zoom Height] toggles the window between normal size (24x80)
1641 and maximum height.
1642\end{description}
1643
1644The rest of this menu lists the names of all open windows; select one
1645to bring it to the foreground (deiconifying it if necessary).
1646
1647
1648\subsubsection{Debug menu (in the Python Shell window only)}
1649
1650\begin{description}
1651\item[Go to file/line] look around the insert point for a filename
1652 and linenumber, open the file, and show the line.
1653\item[Open stack viewer] show the stack traceback of the last exception
1654\item[Debugger toggle] Run commands in the shell under the debugger
1655\item[JIT Stack viewer toggle] Open stack viewer on traceback
1656\end{description}
1657
1658\index{stack viewer}
1659\index{debugger}
1660
1661
1662\subsection{Basic editing and navigation}
1663
1664\begin{itemize}
1665\item \kbd{Backspace} deletes to the left; \kbd{Del} deletes to the right
1666\item Arrow keys and \kbd{Page Up}/\kbd{Page Down} to move around
1667\item \kbd{Home}/\kbd{End} go to begin/end of line
1668\item \kbd{C-Home}/\kbd{C-End} go to begin/end of file
1669\item Some \program{Emacs} bindings may also work, including \kbd{C-B},
1670 \kbd{C-P}, \kbd{C-A}, \kbd{C-E}, \kbd{C-D}, \kbd{C-L}
1671\end{itemize}
1672
1673
1674\subsubsection{Automatic indentation}
1675
1676After a block-opening statement, the next line is indented by 4 spaces
1677(in the Python Shell window by one tab). After certain keywords
1678(break, return etc.) the next line is dedented. In leading
1679indentation, \kbd{Backspace} deletes up to 4 spaces if they are there.
1680\kbd{Tab} inserts 1-4 spaces (in the Python Shell window one tab).
1681See also the indent/dedent region commands in the edit menu.
1682
1683
1684\subsubsection{Python Shell window}
1685
1686\begin{itemize}
1687\item \kbd{C-C} interrupts executing command
1688\item \kbd{C-D} sends end-of-file; closes window if typed at
1689a \samp{>>>~} prompt
1690\end{itemize}
1691
1692\begin{itemize}
Fred Drake666ca802001-11-16 06:02:55 +00001693\item \kbd{Alt-p} retrieves previous command matching what you have typed
1694\item \kbd{Alt-n} retrieves next
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001695\item \kbd{Return} while on any previous command retrieves that command
Fred Drake666ca802001-11-16 06:02:55 +00001696\item \kbd{Alt-/} (Expand word) is also useful here
Fred Drake7cf4e5b2001-11-15 17:22:04 +00001697\end{itemize}
1698
1699\index{indentation}
1700
1701
1702\subsection{Syntax colors}
1703
1704The coloring is applied in a background ``thread,'' so you may
1705occasionally see uncolorized text. To change the color
1706scheme, edit the \code{[Colors]} section in \file{config.txt}.
1707
1708\begin{description}
1709\item[Python syntax colors:]
1710
1711\begin{description}
1712\item[Keywords] orange
1713\item[Strings ] green
1714\item[Comments] red
1715\item[Definitions] blue
1716\end{description}
1717
1718\item[Shell colors:]
1719\begin{description}
1720\item[Console output] brown
1721\item[stdout] blue
1722\item[stderr] dark green
1723\item[stdin] black
1724\end{description}
1725\end{description}
1726
1727
1728\subsubsection{Command line usage}
1729
1730\begin{verbatim}
1731idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...
1732
1733-c command run this command
1734-d enable debugger
1735-e edit mode; arguments are files to be edited
1736-s run $IDLESTARTUP or $PYTHONSTARTUP first
1737-t title set title of shell window
1738\end{verbatim}
1739
1740If there are arguments:
1741
1742\begin{enumerate}
1743\item If \programopt{-e} is used, arguments are files opened for
1744 editing and \code{sys.argv} reflects the arguments passed to
1745 IDLE itself.
1746
1747\item Otherwise, if \programopt{-c} is used, all arguments are
1748 placed in \code{sys.argv[1:...]}, with \code{sys.argv[0]} set
1749 to \code{'-c'}.
1750
1751\item Otherwise, if neither \programopt{-e} nor \programopt{-c} is
1752 used, the first argument is a script which is executed with
1753 the remaining arguments in \code{sys.argv[1:...]} and
1754 \code{sys.argv[0]} set to the script name. If the script name
1755 is '-', no script is executed but an interactive Python
1756 session is started; the arguments are still available in
1757 \code{sys.argv}.
1758\end{enumerate}
Fred Drakec66ff202001-11-16 01:05:27 +00001759
1760
1761\section{Other Graphical User Interface Packages
1762 \label{other-gui-packages}}
1763
1764
1765There are an number of extension widget sets to \refmodule{Tkinter}.
1766
Fred Drake10cd3152001-11-30 18:17:24 +00001767\begin{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001768\seetitle[http://pmw.sourceforge.net/]{Python megawidgets}{is a
1769toolkit for building high-level compound widgets in Python using the
1770\refmodule{Tkinter} module. It consists of a set of base classes and
1771a library of flexible and extensible megawidgets built on this
1772foundation. These megawidgets include notebooks, comboboxes, selection
1773widgets, paned widgets, scrolled widgets, dialog windows, etc. Also,
1774with the Pmw.Blt interface to BLT, the busy, graph, stripchart, tabset
1775and vector commands are be available.
1776
1777The initial ideas for Pmw were taken from the Tk \code{itcl}
1778extensions \code{[incr Tk]} by Michael McLennan and \code{[incr
1779Widgets]} by Mark Ulferts. Several of the megawidgets are direct
1780translations from the itcl to Python. It offers most of the range of
1781widgets that \code{[incr Widgets]} does, and is almost as complete as
1782Tix, lacking however Tix's fast \class{HList} widget for drawing trees.
1783}
Fred Drake81209952003-07-08 13:44:27 +00001784
1785\seetitle[http://tkinter.effbot.org/]{Tkinter3000 Widget Construction
1786 Kit (WCK)}{%
1787is a library that allows you to write new Tkinter widgets in pure
1788Python. The WCK framework gives you full control over widget
1789creation, configuration, screen appearance, and event handling. WCK
1790widgets can be very fast and light-weight, since they can operate
1791directly on Python data structures, without having to transfer data
1792through the Tk/Tcl layer.}
Fred Drake10cd3152001-11-30 18:17:24 +00001793\end{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001794
1795
Fred Drake666ca802001-11-16 06:02:55 +00001796Tk is not the only GUI for Python, but is however the
Fred Drakec66ff202001-11-16 01:05:27 +00001797most commonly used one.
1798
Fred Drake10cd3152001-11-30 18:17:24 +00001799\begin{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001800\seetitle[http://www.wxwindows.org]{wxWindows}{
1801is a GUI toolkit that combines the most attractive attributes of Qt,
1802Tk, Motif, and GTK+ in one powerful and efficient package. It is
Fred Drakec37b65e2001-11-28 07:26:15 +00001803implemented in \Cpp. wxWindows supports two flavors of \UNIX{}
Fred Drakec66ff202001-11-16 01:05:27 +00001804implementation: GTK+ and Motif, and under Windows, it has a standard
1805Microsoft Foundation Classes (MFC) appearance, because it uses Win32
1806widgets. There is a Python class wrapper, independent of Tkinter.
1807
1808wxWindows is much richer in widgets than \refmodule{Tkinter}, with its
1809help system, sophisticated HTML and image viewers, and other
1810specialized widgets, extensive documentation, and printing capabilities.
1811}
Fred Drake9b414ac2002-05-31 18:21:56 +00001812\seetitle[]{PyQt}{
1813PyQt is a \program{sip}-wrapped binding to the Qt toolkit. Qt is an
1814extensive \Cpp{} GUI toolkit that is available for \UNIX, Windows and
1815Mac OS X. \program{sip} is a tool for generating bindings for \Cpp{}
1816libraries as Python classes, and is specifically designed for Python.
1817An online manual is available at
1818\url{http://www.opendocspublishing.com/pyqt/} (errata are located at
1819\url{http://www.valdyas.org/python/book.html}).
1820}
1821\seetitle[http://www.riverbankcomputing.co.uk/pykde/index.php]{PyKDE}{
1822PyKDE is a \program{sip}-wrapped interface to the KDE desktop
1823libraries. KDE is a desktop environment for \UNIX{} computers; the
1824graphical components are based on Qt.
Fred Drakec66ff202001-11-16 01:05:27 +00001825}
1826\seetitle[http://fxpy.sourceforge.net/]{FXPy}{
1827is a Python extension module which provides an interface to the
1828\citetitle[http://www.cfdrc.com/FOX/fox.html]{FOX} GUI.
1829FOX is a \Cpp{} based Toolkit for developing Graphical User Interfaces
1830easily and effectively. It offers a wide, and growing, collection of
1831Controls, and provides state of the art facilities such as drag and
1832drop, selection, as well as OpenGL widgets for 3D graphical
1833manipulation. FOX also implements icons, images, and user-convenience
1834features such as status line help, and tooltips.
1835
1836Even though FOX offers a large collection of controls already, FOX
1837leverages \Cpp{} to allow programmers to easily build additional Controls
1838and GUI elements, simply by taking existing controls, and creating a
1839derived class which simply adds or redefines the desired behavior.
1840}
Fred Draked50bd6c2003-07-28 14:39:13 +00001841\seetitle[http://www.daa.com.au/\textasciitilde james/software/pygtk/]{PyGTK}{
Fred Drakec66ff202001-11-16 01:05:27 +00001842is a set of bindings for the \ulink{GTK}{http://www.gtk.org/} widget set.
1843It provides an object oriented interface that is slightly higher
1844level than the C one. It automatically does all the type casting and
1845reference counting that you would have to do normally with the C
Fred Drake16ecb212002-10-12 15:02:46 +00001846API. There are also
1847\ulink{bindings}{http://www.daa.com.au/\textasciitilde james/gnome/}
Fred Drakec66ff202001-11-16 01:05:27 +00001848to \ulink{GNOME}{http://www.gnome.org}, and a
1849\ulink{tutorial}
Fred Drake16ecb212002-10-12 15:02:46 +00001850{http://laguna.fmedic.unam.mx/\textasciitilde daniel/pygtutorial/pygtutorial/index.html}
Fred Drakec66ff202001-11-16 01:05:27 +00001851is available.
1852}
Fred Drake10cd3152001-11-30 18:17:24 +00001853\end{seealso*}
Fred Drakec66ff202001-11-16 01:05:27 +00001854
1855% XXX Reference URLs that compare the different UI packages