1 \chapter{Graphical User Interfaces with Tk
\label{tkinter
}}
4 \index{Graphical User Interface
}
8 Tk/Tcl has long been an integral part of Python. It provides a robust
9 and platform independent windowing toolkit, that is available to
10 Python programmers using the
\refmodule{Tkinter
} module, and its
11 extension, the
\refmodule{Tix
} module.
13 The
\refmodule{Tkinter
} module is a thin object--oriented layer on top of
14 Tcl/Tk. To use
\refmodule{Tkinter
}, you don't need to write Tcl code,
15 but you will need to consult the Tk documentation, and occasionally
16 the Tcl documentation.
\refmodule{Tkinter
} is a set of wrappers that
17 implement the Tk widgets as Python classes. In addition, the internal
18 module
\module{\_tkinter} provides a threadsafe mechanism which allows
19 Python and Tcl to interact.
21 Tk is not the only GUI for Python, but is however the most commonly
22 used one; see section~
\ref{other-gui-modules
}, ``Other User Interface
23 Modules and Packages,'' for more information on other GUI toolkits for
26 % Other sections I have in mind are
28 % Freezing Tkinter applications
33 \section{\module{Tkinter
} ---
34 Python interface to Tcl/Tk
}
36 \declaremodule{standard
}{Tkinter
}
37 \modulesynopsis{Interface to Tcl/Tk for graphical user interfaces
}
38 \moduleauthor{Guido van Rossum
}{guido@Python.org
}
40 The
\module{Tkinter
} module (``Tk interface'') is the standard Python
41 interface to the Tk GUI toolkit. Both Tk and
\module{Tkinter
} are
42 available on most
\UNIX{} platforms, as well as on Windows and
43 Macintosh systems. (Tk itself is not part of Python; it is maintained
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.
}
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.
}
57 \seetitle[http://www.nmt.edu/tcc/help/pubs/lang.html
]
58 {Tkinter reference: a GUI for Python
}
59 {On-line reference material.
}
61 \seetitle[http://jtkinter.sourceforge.net
]
63 {The Jython interface to Tkinter.
}
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).
}
71 \subsection{Tkinter Modules
}
73 Most of the time, the
\refmodule{Tkinter
} module is all you really
74 need, but a number of additional modules are available as well. The
75 Tk interface is located in a binary module named
\module{_tkinter
}.
76 This module contains the low-level interface to Tk, and should never
77 be used directly by application programmers. It is usually a shared
78 library (or DLL), but might in some cases be statically linked with
79 the Python interpreter.
81 In addition to the Tk interface module,
\refmodule{Tkinter
} includes a
82 number 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
85 to use Tkinter, all you need to do is to import one module:
97 \begin{classdesc
}{Tk
}{screenName=None, baseName=None, className='Tk', useTk=
1}
98 The
\class{Tk
} class is instantiated without arguments.
99 This creates a toplevel widget of Tk which usually is the main window
100 of an appliation. Each instance has its own associated Tcl interpreter.
101 % FIXME: The following keyword arguments are currently recognized:
102 \versionchanged[The
\var{useTk
} parameter was added
]{2.4}
105 \begin{funcdesc
}{Tcl
}{screenName=None, baseName=None, className='Tk', useTk=
0}
106 The
\function{Tcl
} function is a factory function which creates an object
107 much like that created by the
\class{Tk
} class, except that it does not
108 initialize the Tk subsystem. This is most often useful when driving the Tcl
109 interpreter in an environment where one doesn't want to create extraneous
110 toplevel windows, or where one cannot (i.e. Unix/Linux systems without an X
111 server). An object created by the
\function{Tcl
} object can have a Toplevel
112 window created (and the Tk subsystem initialized) by calling its
113 \method{loadtk
} method.
117 Other modules that provide Tk support include:
120 % \declaremodule{standard}{Tkconstants}
121 % \modulesynopsis{Constants used by Tkinter}
124 \item[\refmodule{ScrolledText
}]
125 Text widget with a vertical scroll bar built in.
127 \item[\module{tkColorChooser
}]
128 Dialog to let the user choose a
color.
130 \item[\module{tkCommonDialog
}]
131 Base class for the dialogs defined in the other modules listed here.
133 \item[\module{tkFileDialog
}]
134 Common dialogs to allow the user to specify a file to open or save.
136 \item[\module{tkFont
}]
137 Utilities to help work with fonts.
139 \item[\module{tkMessageBox
}]
140 Access to standard Tk dialog boxes.
142 \item[\module{tkSimpleDialog
}]
143 Basic dialogs and convenience functions.
145 \item[\module{Tkdnd
}]
146 Drag-and-drop support for
\refmodule{Tkinter
}.
147 This is experimental and should become deprecated when it is replaced
150 \item[\refmodule{turtle
}]
151 Turtle graphics in a Tk window.
155 \subsection{Tkinter Life Preserver
}
156 \sectionauthor{Matt Conway
}{}
157 % Converted to LaTeX by Mike Clarkson.
159 This section is not designed to be an exhaustive tutorial on either
160 Tk or Tkinter. Rather, it is intended as a stop gap, providing some
161 introductory orientation on the system.
165 \item Tkinter was written by Steen Lumholt and Guido van Rossum.
166 \item Tk was written by John Ousterhout while at Berkeley.
167 \item This Life Preserver was written by Matt Conway at
168 the University of Virginia.
169 \item The html rendering, and some liberal editing, was
170 produced from a FrameMaker version by Ken Manheimer.
171 \item Fredrik Lundh elaborated and revised the class interface descriptions,
172 to get them current with Tk
4.2.
173 \item Mike Clarkson converted the documentation to
\LaTeX, and compiled the
174 User Interface chapter of the reference manual.
178 \subsubsection{How To Use This Section
}
180 This section is designed in two parts: the first half (roughly) covers
181 background material, while the second half can be taken to the
182 keyboard as a handy reference.
184 When trying to answer questions of the form ``how do I do blah'', it
185 is often best to find out how to do``blah'' in straight Tk, and then
186 convert this back into the corresponding
\refmodule{Tkinter
} call.
187 Python programmers can often guess at the correct Python command by
188 looking at the Tk documentation. This means that in order to use
189 Tkinter, you will have to know a little bit about Tk. This
document
190 can't fulfill that role, so the best we can do is point you to the
191 best documentation that exists. Here are some hints:
194 \item The authors strongly suggest getting a copy of the Tk man
195 pages. Specifically, the man pages in the
\code{mann
} directory are most
196 useful. The
\code{man3
} man pages describe the C interface to the Tk
197 library and thus are not especially helpful for script writers.
199 \item Addison-Wesley publishes a book called
\citetitle{Tcl and the
200 Tk Toolkit
} by John Ousterhout (ISBN
0-
201-
63337-X) which is a good
201 introduction to Tcl and Tk for the novice. The book is not
202 exhaustive, and for many details it defers to the man pages.
204 \item \file{Tkinter.py
} is a last resort for most, but can be a good
205 place to go when nothing else makes sense.
209 \seetitle[http://tcl.activestate.com/
]
210 {ActiveState Tcl Home Page
}
211 {The Tk/Tcl development is largely taking place at
213 \seetitle[http://www.amazon.com/exec/obidos/ASIN/
020163337X
]
214 {Tcl and the Tk Toolkit
}
215 {The book by John Ousterhout, the inventor of Tcl .
}
216 \seetitle[http://www.amazon.com/exec/obidos/ASIN/
0130220280]
217 {Practical Programming in Tcl and Tk
}
218 {Brent Welch's encyclopedic book.
}
222 \subsubsection{A Simple Hello World Program
} % HelloWorld.html
225 %\begin{figure}[hbtp]
226 %\centerline{\epsfig{file=HelloWorld.gif,width=.9\textwidth}}
228 %\caption{HelloWorld gadget image}
230 %See also the hello-world \ulink{notes}{classes/HelloWorld-notes.html} and
231 %\ulink{summary}{classes/HelloWorld-summary.html}.
236 from Tkinter import *
238 class Application(Frame):
240 print "hi there, everyone!"
242 def createWidgets(self):
243 self.QUIT = Button(self)
244 self.QUIT
["text"
] = "QUIT"
245 self.QUIT
["fg"
] = "red"
246 self.QUIT
["command"
] = self.quit
248 self.QUIT.pack(
{"side": "left"
})
250 self.hi_there = Button(self)
251 self.hi_there
["text"
] = "Hello",
252 self.hi_there
["command"
] = self.say_hi
254 self.hi_there.pack(
{"side": "left"
})
256 def __init__(self, master=None):
257 Frame.__init__(self, master)
266 \subsection{A (Very) Quick Look at Tcl/Tk
} % BriefTclTk.html
268 The class hierarchy looks complicated, but in actual practice,
269 application programmers almost always refer to the classes at the very
270 bottom of the hierarchy.
274 \item These classes are provided for the purposes of
275 organizing certain functions under one namespace. They aren't meant to
276 be instantiated independently.
278 \item The
\class{Tk
} class is meant to be instantiated only once in
279 an application. Application programmers need not instantiate one
280 explicitly, the system creates one whenever any of the other classes
283 \item The
\class{Widget
} class is not meant to be instantiated, it
284 is meant only for subclassing to make ``real'' widgets (in
\Cpp, this
285 is called an `abstract class').
288 To make use of this reference material, there will be times when you
289 will need to know how to read short passages of Tk and how to identify
290 the various parts of a Tk command.
291 (See section~
\ref{tkinter-basic-mapping
} for the
292 \refmodule{Tkinter
} equivalents of what's below.)
294 Tk scripts are Tcl programs. Like all Tcl programs, Tk scripts are
295 just lists of tokens separated by spaces. A Tk widget is just its
296 \emph{class
}, the
\emph{options
} that help configure it, and the
297 \emph{actions
} that make it do useful things.
299 To make a widget in Tk, the command is always of the form:
302 classCommand newPathname options
306 \item[\var{classCommand
}]
307 denotes which kind of widget to make (a button, a label, a menu...)
309 \item[\var{newPathname
}]
310 is the new name for this widget. All names in Tk must be unique. To
311 help enforce this, widgets in Tk are named with
\emph{pathnames
}, just
312 like files in a file system. The top level widget, the
\emph{root
},
313 is called
\code{.
} (period) and children are delimited by more
314 periods. For example,
\code{.myApp.controlPanel.okButton
} might be
315 the name of a widget.
317 \item[\var{options
} ]
318 configure the widget's appearance and in some cases, its
319 behavior. The options come in the form of a list of flags and values.
320 Flags are proceeded by a `-', like unix shell command flags, and
321 values are put in quotes if they are more than one word.
327 button .fred -fg red -text "hi there"
328 ^ ^
\_____________________/
331 command widget (-opt val -opt val ...)
334 Once created, the pathname to the widget becomes a new command. This
335 new
\var{widget command
} is the programmer's handle for getting the new
336 widget to perform some
\var{action
}. In C, you'd express this as
337 someAction(fred, someOptions), in
\Cpp, you would express this as
338 fred.someAction(someOptions), and in Tk, you say:
341 .fred someAction someOptions
344 Note that the object name,
\code{.fred
}, starts with a dot.
346 As you'd expect, the legal values for
\var{someAction
} will depend on
347 the widget's class:
\code{.fred disable
} works if fred is a
348 button (fred gets greyed out), but does not work if fred is a label
349 (disabling of labels is not supported in Tk).
351 The legal values of
\var{someOptions
} is action dependent. Some
352 actions, like
\code{disable
}, require no arguments, others, like
353 a text-entry box's
\code{delete
} command, would need arguments
354 to specify what range of text to delete.
357 \subsection{Mapping Basic Tk into Tkinter
358 \label{tkinter-basic-mapping
}}
360 Class commands in Tk correspond to class constructors in Tkinter.
363 button .fred =====> fred = Button()
366 The master of an object is implicit in the new name given to it at
367 creation time. In Tkinter, masters are specified explicitly.
370 button .panel.fred =====> fred = Button(panel)
373 The configuration options in Tk are given in lists of hyphened tags
374 followed by values. In Tkinter, options are specified as
375 keyword-arguments in the instance constructor, and keyword-args for
376 configure calls or as instance indices, in dictionary style, for
377 established instances. See section~
\ref{tkinter-setting-options
} on
381 button .fred -fg red =====> fred = Button(panel, fg = "red")
382 .fred configure -fg red =====> fred
["fg"
] = red
383 OR ==> fred.config(fg = "red")
386 In Tk, to perform an action on a widget, use the widget name as a
387 command, and follow it with an action name, possibly with arguments
388 (options). In Tkinter, you call methods on the class instance to
389 invoke actions on the widget. The actions (methods) that a given
390 widget can perform are listed in the Tkinter.py module.
393 .fred invoke =====> fred.invoke()
396 To give a widget to the packer (geometry manager), you call pack with
397 optional arguments. In Tkinter, the Pack class holds all this
398 functionality, and the various forms of the pack command are
399 implemented as methods. All widgets in
\refmodule{Tkinter
} are
400 subclassed from the Packer, and so inherit all the packing
401 methods. See the
\refmodule{Tix
} module documentation for additional
402 information on the Form geometry manager.
405 pack .fred -side left =====> fred.pack(side = "left")
409 \subsection{How Tk and Tkinter are Related
} % Relationship.html
411 \note{This was derived from a graphical image; the image will be used
412 more directly in a subsequent version of this
document.
}
416 \item[\b{Your App Here (Python)
}]
417 A Python application makes a
\refmodule{Tkinter
} call.
419 \item[\b{Tkinter (Python Module)
}]
420 This call (say, for example, creating a button widget), is
421 implemented in the
\emph{Tkinter
} module, which is written in
422 Python. This Python function will parse the commands and the
423 arguments and convert them into a form that makes them look as if they
424 had come from a Tk script instead of a Python script.
426 \item[\b{tkinter (C)
}]
427 These commands and their arguments will be passed to a C function
428 in the
\emph{tkinter
} - note the lowercase - extension module.
430 \item[\b{Tk Widgets
} (C and Tcl)
]
431 This C function is able to make calls into other C modules,
432 including the C functions that make up the Tk library. Tk is
433 implemented in C and some Tcl. The Tcl part of the Tk widgets is used
434 to bind certain default behaviors to widgets, and is executed once at
435 the point where the Python
\refmodule{Tkinter
} module is
436 imported. (The user never sees this stage).
439 The Tk part of the Tk Widgets implement the final mapping to ...
442 the Xlib library to draw graphics on the screen.
446 \subsection{Handy Reference
}
448 \subsubsection{Setting Options
449 \label{tkinter-setting-options
}}
451 Options control things like the
color and border width of a widget.
452 Options can be set in three ways:
455 \item[At object creation time, using keyword arguments
]:
457 fred = Button(self, fg = "red", bg = "blue")
459 \item[After object creation, treating the option name like a dictionary index
]:
464 \item[Use the config() method to update multiple attrs subesequent to
467 fred.config(fg = "red", bg = "blue")
471 For a complete explanation of a given option and its behavior, see the
472 Tk man pages for the widget in question.
474 Note that the man pages list "STANDARD OPTIONS" and "WIDGET SPECIFIC
475 OPTIONS" for each widget. The former is a list of options that are
476 common to many widgets, the latter are the options that are
477 ideosyncratic to that particular widget. The Standard Options are
478 documented on the
\manpage{options
}{3} man page.
480 No distinction between standard and widget-specific options is made in
481 this
document. Some options don't apply to some kinds of widgets.
482 Whether a given widget responds to a particular option depends on the
483 class of the widget; buttons have a
\code{command
} option, labels do not.
485 The options supported by a given widget are listed in that widget's
486 man page, or can be queried at runtime by calling the
487 \method{config()
} method without arguments, or by calling the
488 \method{keys()
} method on that widget. The return value of these
489 calls is a dictionary whose key is the name of the option as a string
490 (for example,
\code{'relief'
}) and whose values are
5-tuples.
492 Some options, like
\code{bg
} are synonyms for common options with long
493 names (
\code{bg
} is shorthand for "background"). Passing the
494 \code{config()
} method the name of a shorthand option will return a
495 2-tuple, not
5-tuple. The
2-tuple passed back will contain the name of
496 the synonym and the ``real'' option (such as
\code{('bg',
499 \begin{tableiii
}{c|l|l
}{textrm
}{Index
}{Meaning
}{Example
}
500 \lineiii{0}{option name
} {\code{'relief'
}}
501 \lineiii{1}{option name for database lookup
} {\code{'relief'
}}
502 \lineiii{2}{option class for database lookup
} {\code{'Relief'
}}
503 \lineiii{3}{default value
} {\code{'raised'
}}
504 \lineiii{4}{current value
} {\code{'groove'
}}
511 >>> print fred.config()
512 {'relief' : ('relief', 'relief', 'Relief', 'raised', 'groove')
}
515 Of course, the dictionary printed will include all the options
516 available and their values. This is meant only as an example.
519 \subsubsection{The Packer
} % Packer.html
520 \index{packing (widgets)
}
522 The packer is one of Tk's geometry-management mechanisms. See also
523 \citetitle[classes/ClassPacker.html
]{the Packer class interface
}.
525 Geometry managers are used to specify the relative positioning of the
526 positioning of widgets within their container - their mutual
527 \emph{master
}. In contrast to the more cumbersome
\emph{placer
}
528 (which is used less commonly, and we do not cover here), the packer
529 takes qualitative relationship specification -
\emph{above
},
\emph{to
530 the left of
},
\emph{filling
}, etc - and works everything out to
531 determine the exact placement coordinates for you.
533 The size of any
\emph{master
} widget is determined by the size of
534 the "slave widgets" inside. The packer is used to control where slave
535 widgets appear inside the master into which they are packed. You can
536 pack widgets into frames, and frames into other frames, in order to
537 achieve the kind of layout you desire. Additionally, the arrangement
538 is dynamically adjusted to accomodate incremental changes to the
539 configuration, once it is packed.
541 Note that widgets do not appear until they have had their geometry
542 specified with a geometry manager. It's a common early mistake to
543 leave out the geometry specification, and then be surprised when the
544 widget is created but nothing appears. A widget will appear only
545 after it has had, for example, the packer's
\method{pack()
} method
548 The pack() method can be called with keyword-option/value pairs that
549 control where the widget is to appear within its container, and how it
550 is to behave when the main application window is resized. Here are
554 fred.pack() # defaults to side = "top"
555 fred.pack(side = "left")
556 fred.pack(expand =
1)
560 \subsubsection{Packer Options
}
562 For more extensive information on the packer and the options that it
563 can take, see the man pages and page
183 of John Ousterhout's book.
567 Anchor type. Denotes where the packer is to place each slave in its
571 Boolean,
\code{0} or
\code{1}.
574 Legal values:
\code{'x'
},
\code{'y'
},
\code{'both'
},
\code{'none'
}.
576 \item[\b{ipadx
} and
\b{ipady
}]
577 A distance - designating internal padding on each side of the slave
580 \item[\b{padx
} and
\b{pady
}]
581 A distance - designating external padding on each side of the slave
585 Legal values are:
\code{'left'
},
\code{'right'
},
\code{'top'
},
590 \subsubsection{Coupling Widget Variables
} % VarCouplings.html
592 The current-value setting of some widgets (like text entry widgets)
593 can be connected directly to application variables by using special
594 options. These options are
\code{variable
},
\code{textvariable
},
595 \code{onvalue
},
\code{offvalue
}, and
\code{value
}. This
596 connection works both ways: if the variable changes for any reason,
597 the widget it's connected to will be updated to reflect the new value.
599 Unfortunately, in the current implementation of
\refmodule{Tkinter
} it is
600 not possible to hand over an arbitrary Python variable to a widget
601 through a
\code{variable
} or
\code{textvariable
} option. The only
602 kinds of variables for which this works are variables that are
603 subclassed from a class called Variable, defined in the
604 \refmodule{Tkinter
} module.
606 There are many useful subclasses of Variable already defined:
607 \class{StringVar
},
\class{IntVar
},
\class{DoubleVar
}, and
608 \class{BooleanVar
}. To read the current value of such a variable,
609 call the
\method{get()
} method on
610 it, and to change its value you call the
\method{set()
} method. If
611 you follow this protocol, the widget will always track the value of
612 the variable, with no further intervention on your part.
617 def __init__(self, master=None):
618 Frame.__init__(self, master)
621 self.entrythingy = Entry()
622 self.entrythingy.pack()
625 # here is the application variable
626 self.contents = StringVar()
627 # set it to some value
628 self.contents.set("this is a variable")
629 # tell the entry widget to watch this variable
630 self.entrythingy
["textvariable"
] = self.contents
632 # and here we get a callback when the user hits return.
633 # we will have the program print out the value of the
634 # application variable when the user hits return
635 self.entrythingy.bind('<Key-Return>',
638 def print_contents(self, event):
639 print "hi. contents of entry is now ---->", \
644 \subsubsection{The Window Manager
} % WindowMgr.html
645 \index{window manager (widgets)
}
647 In Tk, there is a utility command,
\code{wm
}, for interacting with the
648 window manager. Options to the
\code{wm
} command allow you to control
649 things like titles, placement, icon bitmaps, and the like. In
650 \refmodule{Tkinter
}, these commands have been implemented as methods
651 on the
\class{Wm
} class. Toplevel widgets are subclassed from the
652 \class{Wm
} class, and so can call the
\class{Wm
} methods directly.
654 %See also \citetitle[classes/ClassWm.html]{the Wm class interface}.
656 To get at the toplevel window that contains a given widget, you can
657 often just refer to the widget's master. Of course if the widget has
658 been packed inside of a frame, the master won't represent a toplevel
659 window. To get at the toplevel window that contains an arbitrary
660 widget, you can call the
\method{_root()
} method. This
661 method begins with an underscore to denote the fact that this function
662 is part of the implementation, and not an interface to Tk functionality.
664 Here are some examples of typical usage:
669 def __init__(self, master=None):
670 Frame.__init__(self, master)
674 # create the application
678 # here are method calls to the window manager class
680 myapp.master.title("My Do-Nothing Application")
681 myapp.master.maxsize(
1000,
400)
688 \subsubsection{Tk Option Data Types
} % OptionTypes.html
690 \index{Tk Option Data Types
}
694 Legal values are points of the compass:
\code{"n"
},
695 \code{"ne"
},
\code{"e"
},
\code{"se"
},
\code{"s"
},
696 \code{"sw"
},
\code{"w"
},
\code{"nw"
}, and also
700 There are eight built-in, named bitmaps:
\code{'error'
},
\code{'gray25'
},
701 \code{'gray50'
},
\code{'hourglass'
},
\code{'info'
},
\code{'questhead'
},
702 \code{'question'
},
\code{'warning'
}. To specify an X bitmap
703 filename, give the full path to the file, preceded with an
\code{@
},
704 as in
\code{"@/usr/contrib/bitmap/gumby.bit"
}.
707 You can pass integers
0 or
1 or the strings
\code{"yes"
} or
\code{"no"
} .
710 This is any Python function that takes no arguments. For example:
714 fred
["command"
] = print_it
718 Colors can be given as the names of X colors in the rgb.txt file,
719 or as strings representing RGB values in
4 bit:
\code{"\#RGB"
},
8
720 bit:
\code{"\#RRGGBB"
},
12 bit"
\code{"\#RRRGGGBBB"
}, or
16 bit
721 \code{"\#RRRRGGGGBBBB"
} ranges, where R,G,B here represent any
722 legal hex digit. See page
160 of Ousterhout's book for details.
725 The standard X cursor names from
\file{cursorfont.h
} can be used,
726 without the
\code{XC_
} prefix. For example to get a hand cursor
727 (
\constant{XC_hand2
}), use the string
\code{"hand2"
}. You can also
728 specify a bitmap and mask file of your own. See page
179 of
732 Screen distances can be specified in either pixels or absolute
733 distances. Pixels are given as numbers and absolute distances as
734 strings, with the trailing character denoting units:
\code{c
}
735 for centimeters,
\code{i
} for inches,
\code{m
} for millimeters,
736 \code{p
} for printer's points. For example,
3.5 inches is expressed
740 Tk uses a list font name format, such as
\code{\
{courier
10 bold\
}}.
741 Font sizes with positive numbers are measured in points;
742 sizes with negative numbers are measured in pixels.
745 This is a string of the form
\samp{\var{width
}x
\var{height
}}, where
746 width and height are measured in pixels for most widgets (in
747 characters for widgets displaying text). For example:
748 \code{fred
["geometry"
] = "
200x100"
}.
751 Legal values are the strings:
\code{"left"
},
752 \code{"center"
},
\code{"right"
}, and
\code{"fill"
}.
755 This is a string with four space-delimited elements, each of
756 which is a legal distance (see above). For example:
\code{"
2 3 4
757 5"
} and
\code{"
3i
2i
4.5i
2i"
} and
\code{"
3c
2c
4c
10.43c"
}
758 are all legal regions.
761 Determines what the border style of a widget will be. Legal
762 values are:
\code{"raised"
},
\code{"sunken"
},
763 \code{"flat"
},
\code{"groove"
}, and
\code{"ridge"
}.
766 This is almost always the
\method{set()
} method of some scrollbar
767 widget, but can be any widget method that takes a single argument.
768 Refer to the file
\file{Demo/tkinter/matt/canvas-with-scrollbars.py
}
769 in the Python source distribution for an example.
772 Must be one of:
\code{"none"
},
\code{"char"
}, or
\code{"word"
}.
776 \subsubsection{Bindings and Events
} % Bindings.html
778 \index{bind (widgets)
}
779 \index{events (widgets)
}
781 The bind method from the widget command allows you to watch for
782 certain events and to have a callback function trigger when that event
783 type occurs. The form of the bind method is:
786 def bind(self, sequence, func, add=''):
792 is a string that denotes the target kind of event. (See the bind
793 man page and page
201 of John Ousterhout's book for details).
796 is a Python function, taking one argument, to be invoked when the
797 event occurs. An Event instance will be passed as the argument.
798 (Functions deployed this way are commonly known as
\var{callbacks
}.)
801 is optional, either
\samp{} or
\samp{+
}. Passing an empty string
802 denotes that this binding is to replace any other bindings that this
803 event is associated with. Preceeding with a
\samp{+
} means that this
804 function is to be added to the list of functions bound to this event type.
809 def turnRed(self, event):
810 event.widget
["activeforeground"
] = "red"
812 self.button.bind("<Enter>", self.turnRed)
815 Notice how the widget field of the event is being accesed in the
816 \method{turnRed()
} callback. This field contains the widget that
817 caught the X event. The following table lists the other event fields
818 you can access, and how they are denoted in Tk, which can be useful
819 when referring to the Tk man pages.
822 Tk Tkinter Event Field Tk Tkinter Event Field
823 -- ------------------- -- -------------------
825 %h height %E send_event
827 %s state %N keysym_num
835 \subsubsection{The index Parameter
} % Index.html
837 A number of widgets require``index'' parameters to be passed. These
838 are used to point at a specific place in a Text widget, or to
839 particular characters in an Entry widget, or to particular menu items
843 \item[\b{Entry widget indexes (index, view index, etc.)
}]
844 Entry widgets have options that refer to character positions in the
845 text being displayed. You can use these
\refmodule{Tkinter
} functions
846 to access these special points in text widgets:
850 refers to the last position in the text
853 refers to the point where the text cursor is
856 indicates the beginning point of the selected text
859 denotes the last point of the selected text and finally
861 \item[At(x
\optional{, y
})
]
862 refers to the character at pixel location
\var{x
},
\var{y
} (with
863 \var{y
} not used in the case of a text entry widget, which contains a
864 single line of text).
867 \item[\b{Text widget indexes
}]
868 The index notation for Text widgets is very rich and is best described
871 \item[\b{Menu indexes (menu.invoke(), menu.entryconfig(), etc.)
}]
873 Some options and methods for menus manipulate specific menu entries.
874 Anytime a menu index is needed for an option or a parameter, you may
877 \item an integer which refers to the numeric position of the entry in
878 the widget, counted from the top, starting with
0;
879 \item the string
\code{'active'
}, which refers to the menu position that is
880 currently under the cursor;
881 \item the string
\code{"last"
} which refers to the last menu
883 \item An integer preceded by
\code{@
}, as in
\code{@
6}, where the integer is
884 interpreted as a y pixel coordinate in the menu's coordinate system;
885 \item the string
\code{"none"
}, which indicates no menu entry at all, most
886 often used with menu.activate() to deactivate all entries, and
888 \item a text string that is pattern matched against the label of the
889 menu entry, as scanned from the top of the menu to the bottom. Note
890 that this index type is considered after all the others, which means
891 that matches for menu items labelled
\code{last
},
\code{active
}, or
892 \code{none
} may be interpreted as the above literals, instead.
896 \subsubsection{Images
}
898 Bitmap/Pixelmap images can be created through the subclasses of
899 \class{Tkinter.Image
}:
902 \item \class{BitmapImage
} can be used for X11 bitmap data.
903 \item \class{PhotoImage
} can be used for GIF and PPM/PGM
color bitmaps.
906 Either type of image is created through either the
\code{file
} or the
907 \code{data
} option (other options are available as well).
909 The image object can then be used wherever an
\code{image
} option is
910 supported by some widget (e.g. labels, buttons, menus). In these
911 cases, Tk will not keep a reference to the image. When the last Python
912 reference to the image object is deleted, the image data is deleted as
913 well, and Tk will display an empty box wherever the image was used.
915 \section{\module{Tix
} ---
916 Extension widgets for Tk
}
918 \declaremodule{standard
}{Tix
}
919 \modulesynopsis{Tk Extension Widgets for Tkinter
}
920 \sectionauthor{Mike Clarkson
}{mikeclarkson@users.sourceforge.net
}
924 The
\module{Tix
} (Tk Interface Extension) module provides an
925 additional rich set of widgets. Although the standard Tk library has
926 many useful widgets, they are far from complete. The
\module{Tix
}
927 library provides most of the commonly needed widgets that are missing
928 from standard Tk:
\class{HList
},
\class{ComboBox
},
\class{Control
}
929 (a.k.a. SpinBox) and an assortment of scrollable widgets.
\module{Tix
}
930 also includes many more widgets that are generally useful in a wide
931 range of applications:
\class{NoteBook
},
\class{FileEntry
},
932 \class{PanedWindow
}, etc; there are more than
40 of them.
934 With all these new widgets, you can introduce new interaction
935 techniques into applications, creating more useful and more intuitive
936 user interfaces. You can design your application by choosing the most
937 appropriate widgets to match the special needs of your application and
941 \seetitle[http://tix.sourceforge.net/
]
943 {The home page for
\module{Tix
}. This includes links to
944 additional documentation and downloads.
}
945 \seetitle[http://tix.sourceforge.net/dist/current/man/
]
947 {On-line version of the man pages and reference material.
}
948 \seetitle[http://tix.sourceforge.net/dist/current/docs/tix-book/tix.book.html
]
949 {Tix Programming Guide
}
950 {On-line version of the programmer's reference material.
}
951 \seetitle[http://tix.sourceforge.net/Tide/
]
952 {Tix Development Applications
}
953 {Tix applications for development of Tix and Tkinter programs.
954 Tide applications work under Tk or Tkinter, and include
955 \program{TixInspect
}, an inspector to remotely modify and
956 debug Tix/Tk/Tkinter applications.
}
960 \subsection{Using Tix
}
962 \begin{classdesc
}{Tix
}{screenName
\optional{, baseName
\optional{, className
}}}
963 Toplevel widget of Tix which represents mostly the main window
964 of an application. It has an associated Tcl interpreter.
966 Classes in the
\refmodule{Tix
} module subclasses the classes in the
967 \refmodule{Tkinter
} module. The former imports the latter, so to use
968 \refmodule{Tix
} with Tkinter, all you need to do is to import one
969 module. In general, you can just import
\refmodule{Tix
}, and replace
970 the toplevel call to
\class{Tkinter.Tk
} with
\class{Tix.Tk
}:
973 from Tkconstants import *
978 To use
\refmodule{Tix
}, you must have the
\refmodule{Tix
} widgets installed,
979 usually alongside your installation of the Tk widgets.
980 To test your installation, try the following:
984 root.tk.eval('package require Tix')
987 If this fails, you have a Tk installation problem which must be
988 resolved before proceeding. Use the environment variable
\envvar{TIX_LIBRARY
}
989 to point to the installed
\refmodule{Tix
} library directory, and
990 make sure you have the dynamic object library (
\file{tix8183.dll
} or
991 \file{libtix8183.so
}) in the same directory that contains your Tk
992 dynamic object library (
\file{tk8183.dll
} or
\file{libtk8183.so
}). The
993 directory with the dynamic object library should also have a file
994 called
\file{pkgIndex.tcl
} (case sensitive), which contains the line:
997 package ifneeded Tix
8.1 [list load "
[file join $dir tix8183.dll
]" Tix
]
998 \end{verbatim
} % $ <-- bow to font-lock
1001 \subsection{Tix Widgets
}
1004 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/TixIntro.htm
}
1005 introduces over
40 widget classes to the
\refmodule{Tkinter
}
1006 repertoire. There is a demo of all the
\refmodule{Tix
} widgets in the
1007 \file{Demo/tix
} directory of the standard distribution.
1010 % The Python sample code is still being added to Python, hence commented out
1013 \subsubsection{Basic Widgets
}
1015 \begin{classdesc
}{Balloon
}{}
1017 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixBalloon.htm
}
1018 that pops up over a widget to provide help. When the user moves the
1019 cursor inside a widget to which a Balloon widget has been bound, a
1020 small pop-up window with a descriptive message will be shown on the
1025 % \ulink{Balloon}{http://tix.sourceforge.net/dist/current/demos/samples/Balloon.tcl}
1027 \begin{classdesc
}{ButtonBox
}{}
1028 The
\ulink{ButtonBox
}
1029 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixButtonBox.htm
}
1030 widget creates a box of buttons, such as is commonly used for
\code{Ok
1035 % \ulink{ButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/BtnBox.tcl}
1037 \begin{classdesc
}{ComboBox
}{}
1038 The
\ulink{ComboBox
}
1039 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixComboBox.htm
}
1040 widget is similar to the combo box control in MS Windows. The user can
1041 select a choice by either typing in the entry subwdget or selecting
1042 from the listbox subwidget.
1046 % \ulink{ComboBox}{http://tix.sourceforge.net/dist/current/demos/samples/ComboBox.tcl}
1048 \begin{classdesc
}{Control
}{}
1050 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixControl.htm
}
1051 widget is also known as the
\class{SpinBox
} widget. The user can
1052 adjust the value by pressing the two arrow buttons or by entering the
1053 value directly into the entry. The new value will be checked against
1054 the user-defined upper and lower limits.
1058 % \ulink{Control}{http://tix.sourceforge.net/dist/current/demos/samples/Control.tcl}
1060 \begin{classdesc
}{LabelEntry
}{}
1061 The
\ulink{LabelEntry
}
1062 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelEntry.htm
}
1063 widget packages an entry widget and a label into one mega widget. It
1064 can be used be used to simplify the creation of ``entry-form'' type of
1069 % \ulink{LabelEntry}{http://tix.sourceforge.net/dist/current/demos/samples/LabEntry.tcl}
1071 \begin{classdesc
}{LabelFrame
}{}
1072 The
\ulink{LabelFrame
}
1073 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixLabelFrame.htm
}
1074 widget packages a frame widget and a label into one mega widget. To
1075 create widgets inside a LabelFrame widget, one creates the new widgets
1076 relative to the
\member{frame
} subwidget and manage them inside the
1077 \member{frame
} subwidget.
1081 % \ulink{LabelFrame}{http://tix.sourceforge.net/dist/current/demos/samples/LabFrame.tcl}
1083 \begin{classdesc
}{Meter
}{}
1085 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixMeter.htm
}
1086 widget can be used to show the progress of a background job which may
1087 take a long time to execute.
1091 % \ulink{Meter}{http://tix.sourceforge.net/dist/current/demos/samples/Meter.tcl}
1093 \begin{classdesc
}{OptionMenu
}{}
1094 The
\ulink{OptionMenu
}
1095 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixOptionMenu.htm
}
1096 creates a menu button of options.
1100 % \ulink{OptionMenu}{http://tix.sourceforge.net/dist/current/demos/samples/OptMenu.tcl}
1102 \begin{classdesc
}{PopupMenu
}{}
1103 The
\ulink{PopupMenu
}
1104 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPopupMenu.htm
}
1105 widget can be used as a replacement of the
\code{tk_popup
}
1106 command. The advantage of the
\refmodule{Tix
} \class{PopupMenu
} widget
1107 is it requires less application code to manipulate.
1111 % \ulink{PopupMenu}{http://tix.sourceforge.net/dist/current/demos/samples/PopMenu.tcl}
1113 \begin{classdesc
}{Select
}{}
1115 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixSelect.htm
}
1116 widget is a container of button subwidgets. It can be used to provide
1117 radio-box or check-box style of selection options for the user.
1121 % \ulink{Select}{http://tix.sourceforge.net/dist/current/demos/samples/Select.tcl}
1123 \begin{classdesc
}{StdButtonBox
}{}
1124 The
\ulink{StdButtonBox
}
1125 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixStdButtonBox.htm
}
1126 widget is a group of standard buttons for Motif-like dialog boxes.
1130 % \ulink{StdButtonBox}{http://tix.sourceforge.net/dist/current/demos/samples/StdBBox.tcl}
1133 \subsubsection{File Selectors
}
1135 \begin{classdesc
}{DirList
}{}
1137 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirList.htm
} widget
1138 displays a list view of a directory, its previous directories and its
1139 sub-directories. The user can choose one of the directories displayed
1140 in the list or change to another directory.
1144 % \ulink{DirList}{http://tix.sourceforge.net/dist/current/demos/samples/DirList.tcl}
1146 \begin{classdesc
}{DirTree
}{}
1148 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirTree.htm
}
1149 widget displays a tree view of a directory, its previous directories
1150 and its sub-directories. The user can choose one of the directories
1151 displayed in the list or change to another directory.
1155 % \ulink{DirTree}{http://tix.sourceforge.net/dist/current/demos/samples/DirTree.tcl}
1157 \begin{classdesc
}{DirSelectDialog
}{}
1158 The
\ulink{DirSelectDialog
}
1159 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixDirSelectDialog.htm
}
1160 widget presents the directories in the file system in a dialog
1161 window. The user can use this dialog window to navigate through the
1162 file system to select the desired directory.
1166 % \ulink{DirSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/DirDlg.tcl}
1168 \begin{classdesc
}{DirSelectBox
}{}
1169 The
\class{DirSelectBox
} is similar
1170 to the standard Motif(TM) directory-selection box. It is generally used for
1171 the user to choose a directory. DirSelectBox stores the directories mostly
1172 recently selected into a ComboBox widget so that they can be quickly
1176 \begin{classdesc
}{ExFileSelectBox
}{}
1177 The
\ulink{ExFileSelectBox
}
1178 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixExFileSelectBox.htm
}
1179 widget is usually embedded in a tixExFileSelectDialog widget. It
1180 provides an convenient method for the user to select files. The style
1181 of the
\class{ExFileSelectBox
} widget is very similar to the standard
1182 file dialog on MS Windows
3.1.
1186 %\ulink{ExFileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/EFileDlg.tcl}
1188 \begin{classdesc
}{FileSelectBox
}{}
1189 The
\ulink{FileSelectBox
}
1190 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileSelectBox.htm
}
1191 is similar to the standard Motif(TM) file-selection box. It is
1192 generally used for the user to choose a file. FileSelectBox stores the
1193 files mostly recently selected into a
\class{ComboBox
} widget so that
1194 they can be quickly selected again.
1198 % \ulink{FileSelectDialog}{http://tix.sourceforge.net/dist/current/demos/samples/FileDlg.tcl}
1200 \begin{classdesc
}{FileEntry
}{}
1201 The
\ulink{FileEntry
}
1202 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixFileEntry.htm
}
1203 widget can be used to input a filename. The user can type in the
1204 filename manually. Alternatively, the user can press the button widget
1205 that sits next to the entry, which will bring up a file selection
1210 % \ulink{FileEntry}{http://tix.sourceforge.net/dist/current/demos/samples/FileEnt.tcl}
1213 \subsubsection{Hierachical ListBox
}
1215 \begin{classdesc
}{HList
}{}
1217 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixHList.htm
}
1218 widget can be used to display any data that have a hierarchical
1219 structure, for example, file system directory trees. The list entries
1220 are indented and connected by branch lines according to their places
1225 % \ulink{HList}{http://tix.sourceforge.net/dist/current/demos/samples/HList1.tcl}
1227 \begin{classdesc
}{CheckList
}{}
1228 The
\ulink{CheckList
}
1229 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixCheckList.htm
}
1230 widget displays a list of items to be selected by the user. CheckList
1231 acts similarly to the Tk checkbutton or radiobutton widgets, except it
1232 is capable of handling many more items than checkbuttons or
1237 % \ulink{ CheckList}{http://tix.sourceforge.net/dist/current/demos/samples/ChkList.tcl}
1239 % \ulink{ScrolledHList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList.tcl}
1241 % \ulink{ScrolledHList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/SHList2.tcl}
1243 \begin{classdesc
}{Tree
}{}
1245 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTree.htm
}
1246 widget can be used to display hierachical data in a tree form. The
1247 user can adjust the view of the tree by opening or closing parts of
1252 % \ulink{Tree}{http://tix.sourceforge.net/dist/current/demos/samples/Tree.tcl}
1255 % \ulink{Tree (Dynamic)}{http://tix.sourceforge.net/dist/current/demos/samples/DynTree.tcl}
1258 \subsubsection{Tabular ListBox
}
1260 \begin{classdesc
}{TList
}{}
1262 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixTList.htm
}
1263 widget can be used to display data in a tabular format. The list
1264 entries of a
\class{TList
} widget are similar to the entries in the Tk
1265 listbox widget. The main differences are (
1) the
\class{TList
} widget
1266 can display the list entries in a two dimensional format and (
2) you
1267 can use graphical images as well as multiple colors and fonts for the
1272 % \ulink{ScrolledTList (1)}{http://tix.sourceforge.net/dist/current/demos/samples/STList1.tcl}
1274 % \ulink{ScrolledTList (2)}{http://tix.sourceforge.net/dist/current/demos/samples/STList2.tcl}
1276 % Grid has yet to be added to Python
1277 % \subsubsection{Grid Widget}
1279 % \ulink{Simple Grid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid0.tcl}
1281 % \ulink{ScrolledGrid}{http://tix.sourceforge.net/dist/current/demos/samples/SGrid1.tcl}
1283 % \ulink{Editable Grid}{http://tix.sourceforge.net/dist/current/demos/samples/EditGrid.tcl}
1286 \subsubsection{Manager Widgets
}
1288 \begin{classdesc
}{PanedWindow
}{}
1289 The
\ulink{PanedWindow
}
1290 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixPanedWindow.htm
}
1291 widget allows the user to interactively manipulate the sizes of
1292 several panes. The panes can be arranged either vertically or
1293 horizontally. The user changes the sizes of the panes by dragging the
1294 resize handle between two panes.
1298 % \ulink{PanedWindow}{http://tix.sourceforge.net/dist/current/demos/samples/PanedWin.tcl}
1300 \begin{classdesc
}{ListNoteBook
}{}
1301 The
\ulink{ListNoteBook
}
1302 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixListNoteBook.htm
}
1303 widget is very similar to the
\class{TixNoteBook
} widget: it can be
1304 used to display many windows in a limited space using a notebook
1305 metaphor. The notebook is divided into a stack of pages (windows). At
1306 one time only one of these pages can be shown. The user can navigate
1307 through these pages by choosing the name of the desired page in the
1308 \member{hlist
} subwidget.
1312 % \ulink{ListNoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/ListNBK.tcl}
1314 \begin{classdesc
}{NoteBook
}{}
1315 The
\ulink{NoteBook
}
1316 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixNoteBook.htm
}
1317 widget can be used to display many windows in a limited space using a
1318 notebook metaphor. The notebook is divided into a stack of pages. At
1319 one time only one of these pages can be shown. The user can navigate
1320 through these pages by choosing the visual ``tabs'' at the top of the
1325 % \ulink{NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/NoteBook.tcl}
1328 % \subsubsection{Scrolled Widgets}
1330 % \ulink{ScrolledListBox}{http://tix.sourceforge.net/dist/current/demos/samples/SListBox.tcl}
1332 % \ulink{ScrolledText}{http://tix.sourceforge.net/dist/current/demos/samples/SText.tcl}
1334 % \ulink{ScrolledWindow}{http://tix.sourceforge.net/dist/current/demos/samples/SWindow.tcl}
1336 % \ulink{Canvas Object View}{http://tix.sourceforge.net/dist/current/demos/samples/CObjView.tcl}
1339 \subsubsection{Image Types
}
1341 The
\refmodule{Tix
} module adds:
1345 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/pixmap.htm
}
1346 capabilities to all
\refmodule{Tix
} and
\refmodule{Tkinter
} widgets to
1347 create
color images from XPM files.
1350 % \ulink{XPM Image In Button}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm.tcl}
1353 % \ulink{XPM Image In Menu}{http://tix.sourceforge.net/dist/current/demos/samples/Xpm1.tcl}
1357 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/compound.html
}
1358 image types can be used to create images that consists of multiple
1359 horizontal lines; each line is composed of a series of items (texts,
1360 bitmaps, images or spaces) arranged from left to right. For example, a
1361 compound image can be used to display a bitmap and a text string
1362 simutaneously in a Tk
\class{Button
} widget.
1365 % \ulink{Compound Image In Buttons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg.tcl}
1368 % \ulink{Compound Image In NoteBook}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg2.tcl}
1371 % \ulink{Compound Image Notebook Color Tabs}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg4.tcl}
1374 % \ulink{Compound Image Icons}{http://tix.sourceforge.net/dist/current/demos/samples/CmpImg3.tcl}
1378 \subsubsection{Miscellaneous Widgets
}
1380 \begin{classdesc
}{InputOnly
}{}
1381 The
\ulink{InputOnly
}
1382 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixInputOnly.htm
}
1383 widgets are to accept inputs from the user, which can be done with the
1384 \code{bind
} command (
\UNIX{} only).
1387 \subsubsection{Form Geometry Manager
}
1389 In addition,
\refmodule{Tix
} augments
\refmodule{Tkinter
} by providing:
1391 \begin{classdesc
}{Form
}{}
1393 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tixForm.htm
}
1394 geometry manager based on attachment rules for all Tk widgets.
1399 %\subsection{Tix Class Structure}
1401 %\begin{figure}[hbtp]
1402 %\centerline{\epsfig{file=hierarchy.png,width=.9\textwidth}}
1404 %\caption{The Class Hierarchy of Tix Widgets}
1408 \subsection{Tix Commands
}
1410 \begin{classdesc
}{tixCommand
}{}
1411 The
\ulink{tix commands
}
1412 {http://tix.sourceforge.net/dist/current/man/html/TixCmd/tix.htm
}
1413 provide access to miscellaneous elements of
\refmodule{Tix
}'s internal
1414 state and the
\refmodule{Tix
} application context. Most of the information
1415 manipulated by these methods pertains to the application as a whole,
1416 or to a screen or display, rather than to a particular window.
1418 To view the current settings, the common usage is:
1422 print root.tix_configure()
1426 \begin{methoddesc
}{tix_configure
}{\optional{cnf,
} **kw
}
1427 Query or modify the configuration options of the Tix application
1428 context. If no option is specified, returns a dictionary all of the
1429 available options. If option is specified with no value, then the
1430 method returns a list describing the one named option (this list will
1431 be identical to the corresponding sublist of the value returned if no
1432 option is specified). If one or more option-value pairs are
1433 specified, then the method modifies the given option(s) to have the
1434 given value(s); in this case the method returns an empty string.
1435 Option may be any of the configuration options.
1438 \begin{methoddesc
}{tix_cget
}{option
}
1439 Returns the current value of the configuration option given by
1440 \var{option
}. Option may be any of the configuration options.
1443 \begin{methoddesc
}{tix_getbitmap
}{name
}
1444 Locates a bitmap file of the name
\code{name.xpm
} or
\code{name
} in
1445 one of the bitmap directories (see the
\method{tix_addbitmapdir()
}
1446 method). By using
\method{tix_getbitmap()
}, you can avoid hard
1447 coding the pathnames of the bitmap files in your application. When
1448 successful, it returns the complete pathname of the bitmap file,
1449 prefixed with the character
\samp{@
}. The returned value can be used to
1450 configure the
\code{bitmap
} option of the Tk and Tix widgets.
1453 \begin{methoddesc
}{tix_addbitmapdir
}{directory
}
1454 Tix maintains a list of directories under which the
1455 \method{tix_getimage()
} and
\method{tix_getbitmap()
} methods will
1456 search for image files. The standard bitmap directory is
1457 \file{\$TIX_LIBRARY/bitmaps
}. The
\method{tix_addbitmapdir()
} method
1458 adds
\var{directory
} into this list. By using this method, the image
1459 files of an applications can also be located using the
1460 \method{tix_getimage()
} or
\method{tix_getbitmap()
} method.
1463 \begin{methoddesc
}{tix_filedialog
}{\optional{dlgclass
}}
1464 Returns the file selection dialog that may be shared among different
1465 calls from this application. This method will create a file selection
1466 dialog widget when it is called the first time. This dialog will be
1467 returned by all subsequent calls to
\method{tix_filedialog()
}. An
1468 optional dlgclass parameter can be passed as a string to specified
1469 what type of file selection dialog widget is desired. Possible
1470 options are
\code{tix
},
\code{FileSelectDialog
} or
1471 \code{tixExFileSelectDialog
}.
1475 \begin{methoddesc
}{tix_getimage
}{self, name
}
1476 Locates an image file of the name
\file{name.xpm
},
\file{name.xbm
} or
1477 \file{name.ppm
} in one of the bitmap directories (see the
1478 \method{tix_addbitmapdir()
} method above). If more than one file with
1479 the same name (but different extensions) exist, then the image type is
1480 chosen according to the depth of the X display: xbm images are chosen
1481 on monochrome displays and
color images are chosen on
color
1482 displays. By using
\method{tix_getimage()
}, you can avoid hard coding
1483 the pathnames of the image files in your application. When successful,
1484 this method returns the name of the newly created image, which can be
1485 used to configure the
\code{image
} option of the Tk and Tix widgets.
1488 \begin{methoddesc
}{tix_option_get
}{name
}
1489 Gets the options manitained by the Tix scheme mechanism.
1492 \begin{methoddesc
}{tix_resetoptions
}{newScheme, newFontSet
\optional{,
1494 Resets the scheme and fontset of the Tix application to
1495 \var{newScheme
} and
\var{newFontSet
}, respectively. This affects only
1496 those widgets created after this call. Therefore, it is best to call
1497 the resetoptions method before the creation of any widgets in a Tix
1500 The optional parameter
\var{newScmPrio
} can be given to reset the
1501 priority level of the Tk options set by the Tix schemes.
1503 Because of the way Tk handles the X option database, after Tix has
1504 been has imported and inited, it is not possible to reset the
color
1505 schemes and font sets using the
\method{tix_config()
} method.
1506 Instead, the
\method{tix_resetoptions()
} method must be used.
1511 \section{\module{ScrolledText
} ---
1512 Scrolled Text Widget
}
1514 \declaremodule{standard
}{ScrolledText
}
1516 \modulesynopsis{Text widget with a vertical scroll bar.
}
1517 \sectionauthor{Fred L. Drake, Jr.
}{fdrake@acm.org
}
1519 The
\module{ScrolledText
} module provides a class of the same name
1520 which implements a basic text widget which has a vertical scroll bar
1521 configured to do the ``right thing.'' Using the
\class{ScrolledText
}
1522 class is a lot easier than setting up a text widget and scroll bar
1523 directly. The constructor is the same as that of the
1524 \class{Tkinter.Text
} class.
1526 The text widget and scrollbar are packed together in a
\class{Frame
},
1527 and the methods of the
\class{Grid
} and
\class{Pack
} geometry managers
1528 are acquired from the
\class{Frame
} object. This allows the
1529 \class{ScrolledText
} widget to be used directly to achieve most normal
1530 geometry management behavior.
1532 Should more specific control be necessary, the following attributes
1535 \begin{memberdesc
}[ScrolledText
]{frame
}
1536 The frame which surrounds the text and scroll bar widgets.
1539 \begin{memberdesc
}[ScrolledText
]{vbar
}
1540 The scroll bar widget.
1547 \section{Idle
\label{idle
}}
1549 %\declaremodule{standard}{idle}
1550 %\modulesynopsis{A Python Integrated Developement Environment}
1551 \moduleauthor{Guido van Rossum
}{guido@Python.org
}
1553 Idle is the Python IDE built with the
\refmodule{Tkinter
} GUI toolkit.
1555 \index{Python Editor
}
1556 \index{Integrated Developement Environment
}
1559 IDLE has the following features:
1562 \item coded in
100\% pure Python, using the
\refmodule{Tkinter
} GUI toolkit
1564 \item cross-platform: works on Windows and
\UNIX{} (on Mac OS, there are
1565 currently problems with Tcl/Tk)
1567 \item multi-window text editor with multiple undo, Python colorizing
1568 and many other features, e.g. smart indent and call tips
1570 \item Python shell window (a.k.a. interactive interpreter)
1572 \item debugger (not complete, but you can set breakpoints, view and step)
1578 \subsubsection{File menu
}
1581 \item[New window
] create a new editing window
1582 \item[Open...
] open an existing file
1583 \item[Open module...
] open an existing module (searches sys.path)
1584 \item[Class browser
] show classes and methods in current file
1585 \item[Path browser
] show sys.path directories, modules, classes and methods
1587 \index{Class browser
}
1588 \index{Path browser
}
1591 \item[Save
] save current window to the associated file (unsaved
1592 windows have a * before and after the window title)
1594 \item[Save As...
] save current window to new file, which becomes
1596 \item[Save Copy As...
] save current window to different file
1597 without changing the associated file
1601 \item[Close
] close current window (asks to save if unsaved)
1602 \item[Exit
] close all windows and quit IDLE (asks to save if unsaved)
1606 \subsubsection{Edit menu
}
1609 \item[Undo
] Undo last change to current window (max
1000 changes)
1610 \item[Redo
] Redo last undone change to current window
1614 \item[Cut
] Copy selection into system-wide clipboard; then delete selection
1615 \item[Copy
] Copy selection into system-wide clipboard
1616 \item[Paste
] Insert system-wide clipboard into window
1617 \item[Select All
] Select the entire contents of the edit buffer
1621 \item[Find...
] Open a search dialog box with many options
1622 \item[Find again
] Repeat last search
1623 \item[Find selection
] Search for the string in the selection
1624 \item[Find in Files...
] Open a search dialog box for searching files
1625 \item[Replace...
] Open a search-and-replace dialog box
1626 \item[Go to line
] Ask for a line number and show that line
1630 \item[Indent region
] Shift selected lines right
4 spaces
1631 \item[Dedent region
] Shift selected lines left
4 spaces
1632 \item[Comment out region
] Insert \#\# in front of selected lines
1633 \item[Uncomment region
] Remove leading \# or \#\# from selected lines
1634 \item[Tabify region
] Turns
\emph{leading
} stretches of spaces into tabs
1635 \item[Untabify region
] Turn
\emph{all
} tabs into the right number of spaces
1636 \item[Expand word
] Expand the word you have typed to match another
1637 word in the same buffer; repeat to get a different expansion
1638 \item[Format Paragraph
] Reformat the current blank-line-separated paragraph
1642 \item[Import module
] Import or reload the current module
1643 \item[Run script
] Execute the current file in the __main__ namespace
1646 \index{Import module
}
1650 \subsubsection{Windows menu
}
1653 \item[Zoom Height
] toggles the window between normal size (
24x80)
1657 The rest of this menu lists the names of all open windows; select one
1658 to bring it to the foreground (deiconifying it if necessary).
1661 \subsubsection{Debug menu (in the Python Shell window only)
}
1664 \item[Go to file/line
] look around the insert point for a filename
1665 and linenumber, open the file, and show the line.
1666 \item[Open stack viewer
] show the stack traceback of the last exception
1667 \item[Debugger toggle
] Run commands in the shell under the debugger
1668 \item[JIT Stack viewer toggle
] Open stack viewer on traceback
1671 \index{stack viewer
}
1675 \subsection{Basic editing and navigation
}
1678 \item \kbd{Backspace
} deletes to the left;
\kbd{Del
} deletes to the right
1679 \item Arrow keys and
\kbd{Page Up
}/
\kbd{Page Down
} to move around
1680 \item \kbd{Home
}/
\kbd{End
} go to begin/end of line
1681 \item \kbd{C-Home
}/
\kbd{C-End
} go to begin/end of file
1682 \item Some
\program{Emacs
} bindings may also work, including
\kbd{C-B
},
1683 \kbd{C-P
},
\kbd{C-A
},
\kbd{C-E
},
\kbd{C-D
},
\kbd{C-L
}
1687 \subsubsection{Automatic indentation
}
1689 After a block-opening statement, the next line is indented by
4 spaces
1690 (in the Python Shell window by one tab). After certain keywords
1691 (break, return etc.) the next line is dedented. In leading
1692 indentation,
\kbd{Backspace
} deletes up to
4 spaces if they are there.
1693 \kbd{Tab
} inserts
1-
4 spaces (in the Python Shell window one tab).
1694 See also the indent/dedent region commands in the edit menu.
1697 \subsubsection{Python Shell window
}
1700 \item \kbd{C-C
} interrupts executing command
1701 \item \kbd{C-D
} sends end-of-file; closes window if typed at
1702 a
\samp{>>>~
} prompt
1706 \item \kbd{Alt-p
} retrieves previous command matching what you have typed
1707 \item \kbd{Alt-n
} retrieves next
1708 \item \kbd{Return
} while on any previous command retrieves that command
1709 \item \kbd{Alt-/
} (Expand word) is also useful here
1715 \subsection{Syntax colors
}
1717 The coloring is applied in a background ``thread,'' so you may
1718 occasionally see uncolorized text. To change the
color
1719 scheme, edit the
\code{[Colors
]} section in
\file{config.txt
}.
1722 \item[Python syntax colors:
]
1725 \item[Keywords
] orange
1726 \item[Strings
] green
1728 \item[Definitions
] blue
1731 \item[Shell colors:
]
1733 \item[Console output
] brown
1735 \item[stderr
] dark green
1741 \subsubsection{Command line usage
}
1744 idle.py
[-c command
] [-d
] [-e
] [-s
] [-t title
] [arg
] ...
1746 -c command run this command
1748 -e edit mode; arguments are files to be edited
1749 -s run $IDLESTARTUP or $PYTHONSTARTUP first
1750 -t title set title of shell window
1753 If there are arguments:
1756 \item If
\programopt{-e
} is used, arguments are files opened for
1757 editing and
\code{sys.argv
} reflects the arguments passed to
1760 \item Otherwise, if
\programopt{-c
} is used, all arguments are
1761 placed in
\code{sys.argv
[1:...
]}, with
\code{sys.argv
[0]} set
1764 \item Otherwise, if neither
\programopt{-e
} nor
\programopt{-c
} is
1765 used, the first argument is a script which is executed with
1766 the remaining arguments in
\code{sys.argv
[1:...
]} and
1767 \code{sys.argv
[0]} set to the script name. If the script name
1768 is '-', no script is executed but an interactive Python
1769 session is started; the arguments are still available in
1774 \section{Other Graphical User Interface Packages
1775 \label{other-gui-packages
}}
1778 There are an number of extension widget sets to
\refmodule{Tkinter
}.
1781 \seetitle[http://pmw.sourceforge.net/
]{Python megawidgets
}{is a
1782 toolkit for building high-level compound widgets in Python using the
1783 \refmodule{Tkinter
} module. It consists of a set of base classes and
1784 a library of flexible and extensible megawidgets built on this
1785 foundation. These megawidgets include notebooks, comboboxes, selection
1786 widgets, paned widgets, scrolled widgets, dialog windows, etc. Also,
1787 with the Pmw.Blt interface to BLT, the busy, graph, stripchart, tabset
1788 and vector commands are be available.
1790 The initial ideas for Pmw were taken from the Tk
\code{itcl
}
1791 extensions
\code{[incr Tk
]} by Michael McLennan and
\code{[incr
1792 Widgets
]} by Mark Ulferts. Several of the megawidgets are direct
1793 translations from the itcl to Python. It offers most of the range of
1794 widgets that
\code{[incr Widgets
]} does, and is almost as complete as
1795 Tix, lacking however Tix's fast
\class{HList
} widget for drawing trees.
1798 \seetitle[http://tkinter.effbot.org/
]{Tkinter3000 Widget Construction
1800 is a library that allows you to write new Tkinter widgets in pure
1801 Python. The WCK framework gives you full control over widget
1802 creation, configuration, screen appearance, and event handling. WCK
1803 widgets can be very fast and light-weight, since they can operate
1804 directly on Python data structures, without having to transfer data
1805 through the Tk/Tcl layer.
}
1809 Tk is not the only GUI for Python, but is however the
1810 most commonly used one.
1813 \seetitle[http://www.wxwindows.org
]{wxWindows
}{
1814 is a GUI toolkit that combines the most attractive attributes of Qt,
1815 Tk, Motif, and GTK+ in one powerful and efficient package. It is
1816 implemented in
\Cpp. wxWindows supports two flavors of
\UNIX{}
1817 implementation: GTK+ and Motif, and under Windows, it has a standard
1818 Microsoft Foundation Classes (MFC) appearance, because it uses Win32
1819 widgets. There is a Python class wrapper, independent of Tkinter.
1821 wxWindows is much richer in widgets than
\refmodule{Tkinter
}, with its
1822 help system, sophisticated HTML and image viewers, and other
1823 specialized widgets, extensive documentation, and printing capabilities.
1826 PyQt is a
\program{sip
}-wrapped binding to the Qt toolkit. Qt is an
1827 extensive
\Cpp{} GUI toolkit that is available for
\UNIX, Windows and
1828 Mac OS X.
\program{sip
} is a tool for generating bindings for
\Cpp{}
1829 libraries as Python classes, and is specifically designed for Python.
1830 An online manual is available at
1831 \url{http://www.opendocspublishing.com/pyqt/
} (errata are located at
1832 \url{http://www.valdyas.org/python/book.html
}).
1834 \seetitle[http://www.riverbankcomputing.co.uk/pykde/index.php
]{PyKDE
}{
1835 PyKDE is a
\program{sip
}-wrapped interface to the KDE desktop
1836 libraries. KDE is a desktop environment for
\UNIX{} computers; the
1837 graphical components are based on Qt.
1839 \seetitle[http://fxpy.sourceforge.net/
]{FXPy
}{
1840 is a Python extension module which provides an interface to the
1841 \citetitle[http://www.cfdrc.com/FOX/fox.html
]{FOX
} GUI.
1842 FOX is a
\Cpp{} based Toolkit for developing Graphical User Interfaces
1843 easily and effectively. It offers a wide, and growing, collection of
1844 Controls, and provides state of the art facilities such as drag and
1845 drop, selection, as well as OpenGL widgets for
3D graphical
1846 manipulation. FOX also implements icons, images, and user-convenience
1847 features such as status line help, and tooltips.
1849 Even though FOX offers a large collection of controls already, FOX
1850 leverages
\Cpp{} to allow programmers to easily build additional Controls
1851 and GUI elements, simply by taking existing controls, and creating a
1852 derived class which simply adds or redefines the desired behavior.
1854 \seetitle[http://www.daa.com.au/
\textasciitilde james/software/pygtk/
]{PyGTK
}{
1855 is a set of bindings for the
\ulink{GTK
}{http://www.gtk.org/
} widget set.
1856 It provides an object oriented interface that is slightly higher
1857 level than the C one. It automatically does all the type casting and
1858 reference counting that you would have to do normally with the C
1860 \ulink{bindings
}{http://www.daa.com.au/
\textasciitilde james/gnome/
}
1861 to
\ulink{GNOME
}{http://www.gnome.org
}, and a
1863 {http://laguna.fmedic.unam.mx/
\textasciitilde daniel/pygtutorial/pygtutorial/index.html
}
1868 % XXX Reference URLs that compare the different UI packages