• tkinter.tix —- Extension widgets for Tk
    • Using Tix
    • Tix Widgets
      • Basic Widgets
      • File Selectors
      • Hierarchical ListBox
      • Tabular ListBox
      • Manager Widgets
      • Image Types
      • Miscellaneous Widgets
      • Form Geometry Manager
    • Tix Commands

    tkinter.tix —- Extension widgets for Tk

    Source code:Lib/tkinter/tix.py

    3.6 版后已移除: This Tk extension is unmaintained and should not be used in new code. Usetkinter.ttk instead.


    The tkinter.tix (Tk Interface Extension) module provides an additionalrich set of widgets. Although the standard Tk library has many useful widgets,they are far from complete. The tkinter.tix library provides most of thecommonly needed widgets that are missing from standard Tk: HList,ComboBox, Control (a.k.a. SpinBox) and an assortment ofscrollable widgets.tkinter.tix also includes many more widgets that are generally useful ina wide range of applications: NoteBook, FileEntry,PanedWindow, etc; there are more than 40 of them.

    With all these new widgets, you can introduce new interaction techniques intoapplications, creating more useful and more intuitive user interfaces. You candesign your application by choosing the most appropriate widgets to match thespecial needs of your application and users.

    参见

    • Tix Homepage
    • The home page for Tix. This includes links to additional documentationand downloads.

    • Tix Man Pages

    • On-line version of the man pages and reference material.

    • Tix Programming Guide

    • On-line version of the programmer's reference material.

    • Tix Development Applications

    • Tix applications for development of Tix and Tkinter programs. Tide applicationswork under Tk or Tkinter, and include TixInspect, an inspector toremotely modify and debug Tix/Tk/Tkinter applications.

    Using Tix

    • class tkinter.tix.Tk(screenName=None, baseName=None, className='Tix')
    • Toplevel widget of Tix which represents mostly the main window of anapplication. It has an associated Tcl interpreter.

    Classes in the tkinter.tix module subclasses the classes in thetkinter. The former imports the latter, so to use tkinter.tixwith Tkinter, all you need to do is to import one module. In general, youcan just import tkinter.tix, and replace the toplevel call totkinter.Tk with tix.Tk:

    1. from tkinter import tix
    2. from tkinter.constants import *
    3. root = tix.Tk()

    To use tkinter.tix, you must have the Tix widgets installed, usuallyalongside your installation of the Tk widgets. To test your installation, trythe following:

    1. from tkinter import tix
    2. root = tix.Tk()
    3. root.tk.eval('package require Tix')

    Tix Widgets

    Tixintroduces over 40 widget classes to the tkinter repertoire.

    Basic Widgets

    • class tkinter.tix.Balloon
    • A Balloon thatpops up over a widget to provide help. When the user moves the cursor inside awidget to which a Balloon widget has been bound, a small pop-up window with adescriptive message will be shown on the screen.

    • class tkinter.tix.ButtonBox

    • The ButtonBoxwidget creates a box of buttons, such as is commonly used for Ok Cancel.

    • class tkinter.tix.ComboBox

    • The ComboBoxwidget is similar to the combo box control in MS Windows. The user can select achoice by either typing in the entry subwidget or selecting from the listboxsubwidget.

    • class tkinter.tix.Control

    • The Controlwidget is also known as the SpinBox widget. The user can adjust thevalue by pressing the two arrow buttons or by entering the value directly intothe entry. The new value will be checked against the user-defined upper andlower limits.

    • class tkinter.tix.LabelEntry

    • The LabelEntrywidget packages an entry widget and a label into one mega widget. It canbe used to simplify the creation of "entry-form" type of interface.

    • class tkinter.tix.LabelFrame

    • The LabelFramewidget packages a frame widget and a label into one mega widget. To createwidgets inside a LabelFrame widget, one creates the new widgets relative to theframe subwidget and manage them inside the frame subwidget.

    • class tkinter.tix.Meter

    • The Meter widgetcan be used to show the progress of a background job which may take a long timeto execute.

    • class tkinter.tix.OptionMenu

    • The OptionMenucreates a menu button of options.

    • class tkinter.tix.PopupMenu

    • The PopupMenuwidget can be used as a replacement of the tk_popup command. The advantageof the Tix PopupMenu widget is it requires less application codeto manipulate.

    • class tkinter.tix.Select

    • The Select widgetis a container of button subwidgets. It can be used to provide radio-box orcheck-box style of selection options for the user.

    • class tkinter.tix.StdButtonBox

    • The StdButtonBoxwidget is a group of standard buttons for Motif-like dialog boxes.

    File Selectors

    • class tkinter.tix.DirList
    • The DirListwidget displays a list view of a directory, its previous directories and itssub-directories. The user can choose one of the directories displayed in thelist or change to another directory.

    • class tkinter.tix.DirTree

    • The DirTreewidget displays a tree view of a directory, its previous directories and itssub-directories. The user can choose one of the directories displayed in thelist or change to another directory.

    • class tkinter.tix.DirSelectDialog

    • The DirSelectDialogwidget presents the directories in the file system in a dialog window. The usercan use this dialog window to navigate through the file system to select thedesired directory.

    • class tkinter.tix.DirSelectBox

    • The DirSelectBox is similar to the standard Motif(TM)directory-selection box. It is generally used for the user to choose adirectory. DirSelectBox stores the directories mostly recently selected intoa ComboBox widget so that they can be quickly selected again.

    • class tkinter.tix.ExFileSelectBox

    • The ExFileSelectBoxwidget is usually embedded in a tixExFileSelectDialog widget. It provides aconvenient method for the user to select files. The style of theExFileSelectBox widget is very similar to the standard file dialog onMS Windows 3.1.

    • class tkinter.tix.FileSelectBox

    • The FileSelectBoxis similar to the standard Motif(TM) file-selection box. It is generally usedfor the user to choose a file. FileSelectBox stores the files mostly recentlyselected into a ComboBox widget so that they can be quickly selectedagain.

    • class tkinter.tix.FileEntry

    • The FileEntrywidget can be used to input a filename. The user can type in the filenamemanually. Alternatively, the user can press the button widget that sits next tothe entry, which will bring up a file selection dialog.

    Hierarchical ListBox

    • class tkinter.tix.HList
    • The HList widgetcan be used to display any data that have a hierarchical structure, for example,file system directory trees. The list entries are indented and connected bybranch lines according to their places in the hierarchy.

    • class tkinter.tix.CheckList

    • The CheckListwidget displays a list of items to be selected by the user. CheckList actssimilarly to the Tk checkbutton or radiobutton widgets, except it is capable ofhandling many more items than checkbuttons or radiobuttons.

    • class tkinter.tix.Tree

    • The Tree widgetcan be used to display hierarchical data in a tree form. The user can adjust theview of the tree by opening or closing parts of the tree.

    Tabular ListBox

    • class tkinter.tix.TList
    • The TList widgetcan be used to display data in a tabular format. The list entries of aTList widget are similar to the entries in the Tk listbox widget. Themain differences are (1) the TList widget can display the list entriesin a two dimensional format and (2) you can use graphical images as well asmultiple colors and fonts for the list entries.

    Manager Widgets

    • class tkinter.tix.PanedWindow
    • The PanedWindowwidget allows the user to interactively manipulate the sizes of several panes.The panes can be arranged either vertically or horizontally. The user changesthe sizes of the panes by dragging the resize handle between two panes.

    • class tkinter.tix.ListNoteBook

    • The ListNoteBookwidget is very similar to the TixNoteBook widget: it can be used todisplay many windows in a limited space using a notebook metaphor. The notebookis divided into a stack of pages (windows). At one time only one of these pagescan be shown. The user can navigate through these pages by choosing the name ofthe desired page in the hlist subwidget.

    • class tkinter.tix.NoteBook

    • The NoteBookwidget can be used to display many windows in a limited space using a notebookmetaphor. The notebook is divided into a stack of pages. At one time only one ofthese pages can be shown. The user can navigate through these pages by choosingthe visual "tabs" at the top of the NoteBook widget.

    Image Types

    The tkinter.tix module adds:

    • pixmapcapabilities to all tkinter.tix and tkinter widgets to createcolor images from XPM files.

    • Compound imagetypes can be used to create images that consists of multiple horizontal lines;each line is composed of a series of items (texts, bitmaps, images or spaces)arranged from left to right. For example, a compound image can be used todisplay a bitmap and a text string simultaneously in a Tk Buttonwidget.

    Miscellaneous Widgets

    • class tkinter.tix.InputOnly
    • The InputOnlywidgets are to accept inputs from the user, which can be done with the bindcommand (Unix only).

    Form Geometry Manager

    In addition, tkinter.tix augments tkinter by providing:

    • class tkinter.tix.Form
    • The Form geometrymanager based on attachment rules for all Tk widgets.

    Tix Commands

    • class tkinter.tix.tixCommand
    • The tix commands provideaccess to miscellaneous elements of Tix's internal state and theTix application context. Most of the information manipulated by thesemethods pertains to the application as a whole, or to a screen or display,rather than to a particular window.

    To view the current settings, the common usage is:

    1. from tkinter import tix
    2. root = tix.Tk()
    3. print(root.tix_configure())
    • tixCommand.tixconfigure(_cnf=None, **kw)
    • Query or modify the configuration options of the Tix application context. If nooption is specified, returns a dictionary all of the available options. Ifoption is specified with no value, then the method returns a list describing theone named option (this list will be identical to the corresponding sublist ofthe value returned if no option is specified). If one or more option-valuepairs are specified, then the method modifies the given option(s) to have thegiven value(s); in this case the method returns an empty string. Option may beany of the configuration options.

    • tixCommand.tixcget(_option)

    • Returns the current value of the configuration option given by option. Optionmay be any of the configuration options.

    • tixCommand.tixgetbitmap(_name)

    • Locates a bitmap file of the name name.xpm or name in one of the bitmapdirectories (see the tix_addbitmapdir() method). By usingtix_getbitmap(), you can avoid hard coding the pathnames of the bitmapfiles in your application. When successful, it returns the complete pathname ofthe bitmap file, prefixed with the character @. The returned value can beused to configure the bitmap option of the Tk and Tix widgets.

    • tixCommand.tixaddbitmapdir(_directory)

    • Tix maintains a list of directories under which the tix_getimage() andtix_getbitmap() methods will search for image files. The standard bitmapdirectory is $TIXLIBRARY/bitmaps. The tix_addbitmapdir() methodadds _directory into this list. By using this method, the image files of anapplications can also be located using the tix_getimage() ortix_getbitmap() method.

    • tixCommand.tixfiledialog([_dlgclass])

    • Returns the file selection dialog that may be shared among different calls fromthis application. This method will create a file selection dialog widget whenit is called the first time. This dialog will be returned by all subsequentcalls to tix_filedialog(). An optional dlgclass parameter can be passedas a string to specified what type of file selection dialog widget is desired.Possible options are tix, FileSelectDialog or tixExFileSelectDialog.

    • tixCommand.tixgetimage(_self, name)

    • Locates an image file of the name name.xpm, name.xbm orname.ppm in one of the bitmap directories (see thetix_addbitmapdir() method above). If more than one file with the same name(but different extensions) exist, then the image type is chosen according to thedepth of the X display: xbm images are chosen on monochrome displays and colorimages are chosen on color displays. By using tix_getimage(), you canavoid hard coding the pathnames of the image files in your application. Whensuccessful, this method returns the name of the newly created image, which canbe used to configure the image option of the Tk and Tix widgets.

    • tixCommand.tixoption_get(_name)

    • Gets the options maintained by the Tix scheme mechanism.

    • tixCommand.tixresetoptions(_newScheme, newFontSet[, newScmPrio])

    • Resets the scheme and fontset of the Tix application to newScheme andnewFontSet, respectively. This affects only those widgets created after thiscall. Therefore, it is best to call the resetoptions method before the creationof any widgets in a Tix application.

    The optional parameter newScmPrio can be given to reset the priority level ofthe Tk options set by the Tix schemes.

    Because of the way Tk handles the X option database, after Tix has been hasimported and inited, it is not possible to reset the color schemes and font setsusing the tix_config() method. Instead, the tix_resetoptions()method must be used.