新聞中心
tkinter.tix —- TK擴展包
源代碼: Lib/tkinter/tix.py

3.6 版后已移除: 這個 TK 擴展已無人維護所以請不要在新代碼中使用。 請改用 tkinter.ttk。
tkinter.tix (Tk Interface Extension) 模塊提供了更豐富的額外可視化部件集。 雖然標準 Tk 庫包含許多有用的部件,但還遠不夠完備。 tkinter.tix 庫提供了標準 Tk 所缺少的大量常用部件: HList, ComboBox, Control (即 SpinBox) 以及一系列可滾動的部件。 tkinter.tix 還包括了大量在多種不同領域的應用中很常用的部件: NoteBook, FileEntry, PanedWindow 等等;總共有超過 40 種。
使用這些新增部件,你可以為應用程序引入新的交互技術,創(chuàng)建更好用且更直觀的用戶界面。 你在設計應用程序時可以通過選擇最適合的部件來匹配你的應用程序和用戶的特殊需求。
參見
Tix Homepage
Tix 的主頁。 其中包括附加文檔和下載資源的鏈接。
Tix Man Pages
在線版本的指南頁面和參考材料。
Tix Programming Guide
在線版本的程序員參考材料。
Tix Development Applications
開發(fā) Tix 和 Tkinter 程序的 Tix 應用。 Tide 應用在 Tk 在 Tkinter 下工作,并包括了 TixInspect,這是一個可遠程修改和調試 Tix/Tk/Tkinter 應用的檢查工具。
使用 Tix
class tkinter.tix.Tk(screenName=None, baseName=None, className=’Tix’)
最常用于代表應用主窗口的最高層級部件。 它具有一個相關聯(lián)的 Tcl 解釋器。interpreter.
tkinter.tix 模塊中的類子類化了 tkinter 中的類。 前者會導入后者,因此 tkinter.tix 要使用 Tkinter,你所要做的就是導入一個模塊。 通常,你可以只導入 tkinter.tix,并將最高層級調用由 tkinter.Tk 替換為 tix.Tk:
from tkinter import tixfrom tkinter.constants import *root = tix.Tk()
要使用 tkinter.tix,你必須安裝有 Tix 部件,通常會與你的 Tk 部分一起安裝。 要測試你的安裝,請嘗試以下代碼:
from tkinter import tixroot = tix.Tk()root.tk.eval('package require Tix')
Tix 部件
Tix introduces over 40 widget classes to the tkinter repertoire.
基本部件
class tkinter.tix.Balloon
A Balloon that pops up over a widget to provide help. When the user moves the cursor inside a widget to which a Balloon widget has been bound, a small pop-up window with a descriptive message will be shown on the screen.
class tkinter.tix.ButtonBox
The ButtonBox widget creates a box of buttons, such as is commonly used for Ok Cancel.
class tkinter.tix.ComboBox
The ComboBox widget is similar to the combo box control in MS Windows. The user can select a choice by either typing in the entry subwidget or selecting from the listbox subwidget.
class tkinter.tix.Control
The Control widget is also known as the SpinBox widget. The user can adjust the value by pressing the two arrow buttons or by entering the value directly into the entry. The new value will be checked against the user-defined upper and lower limits.
class tkinter.tix.LabelEntry
The LabelEntry widget packages an entry widget and a label into one mega widget. It can be used to simplify the creation of “entry-form” type of interface.
class tkinter.tix.LabelFrame
The LabelFrame widget packages a frame widget and a label into one mega widget. To create widgets inside a LabelFrame widget, one creates the new widgets relative to the frame subwidget and manage them inside the frame subwidget.
class tkinter.tix.Meter
The Meter widget can be used to show the progress of a background job which may take a long time to execute.
class tkinter.tix.OptionMenu
The OptionMenu creates a menu button of options.
class tkinter.tix.PopupMenu
The PopupMenu widget can be used as a replacement of the tk_popup command. The advantage of the Tix PopupMenu widget is it requires less application code to manipulate.
class tkinter.tix.Select
The Select widget is a container of button subwidgets. It can be used to provide radio-box or check-box style of selection options for the user.
class tkinter.tix.StdButtonBox
The StdButtonBox widget is a group of standard buttons for Motif-like dialog boxes.
文件選擇器
class tkinter.tix.DirList
The DirList widget displays a list view of a directory, its previous directories and its sub-directories. The user can choose one of the directories displayed in the list or change to another directory.
class tkinter.tix.DirTree
The DirTree widget displays a tree view of a directory, its previous directories and its sub-directories. The user can choose one of the directories displayed in the list or change to another directory.
class tkinter.tix.DirSelectDialog
The DirSelectDialog widget presents the directories in the file system in a dialog window. The user can use this dialog window to navigate through the file system to select the desired directory.
class tkinter.tix.DirSelectBox
DirSelectBox 類似于標準的 Motif(TM) 目錄選擇框。 它通常用于讓用戶選擇一個目錄。 DirSelectBox 會將最近選擇的目錄存放在一個 ComboBox 部件中以便可以再次快速地選擇它們。
class tkinter.tix.ExFileSelectBox
The ExFileSelectBox widget is usually embedded in a tixExFileSelectDialog widget. It provides a convenient method for the user to select files. The style of the ExFileSelectBox widget is very similar to the standard file dialog on MS Windows 3.1.
class tkinter.tix.FileSelectBox
The FileSelectBox is similar to the standard Motif(TM) file-selection box. It is generally used for the user to choose a file. FileSelectBox stores the files mostly recently selected into a ComboBox widget so that they can be quickly selected again.
class tkinter.tix.FileEntry
The FileEntry widget can be used to input a filename. The user can type in the filename manually. Alternatively, the user can press the button widget that sits next to the entry, which will bring up a file selection dialog.
層級式列表框
class tkinter.tix.HList
The HList widget can be used to display any data that have a hierarchical structure, for example, file system directory trees. The list entries are indented and connected by branch lines according to their places in the hierarchy.
class tkinter.tix.CheckList
The CheckList widget displays a list of items to be selected by the user. CheckList acts similarly to the Tk checkbutton or radiobutton widgets, except it is capable of handling many more items than checkbuttons or radiobuttons.
class tkinter.tix.Tree
The Tree widget can be used to display hierarchical data in a tree form. The user can adjust the view of the tree by opening or closing parts of the tree.
表格式列表框
class tkinter.tix.TList
The TList widget can be used to display data in a tabular format. The list entries of a TList widget are similar to the entries in the Tk listbox widget. The main differences are (1) the TList widget can display the list entries in a two dimensional format and (2) you can use graphical images as well as multiple colors and fonts for the list entries.
管理器部件
class tkinter.tix.PanedWindow
The PanedWindow widget allows the user to interactively manipulate the sizes of several panes. The panes can be arranged either vertically or horizontally. The user changes the sizes of the panes by dragging the resize handle between two panes.
class tkinter.tix.ListNoteBook
The ListNoteBook widget is very similar to the TixNoteBook widget: it can be used to display many windows in a limited space using a notebook metaphor. The notebook is divided into a stack of pages (windows). At one time only one of these pages can be shown. The user can navigate through these pages by choosing the name of the desired page in the hlist subwidget.
class tkinter.tix.NoteBook
The NoteBook widget can be used to display many windows in a limited space using a notebook metaphor. The notebook is divided into a stack of pages. At one time only one of these pages can be shown. The user can navigate through these pages by choosing the visual “tabs” at the top of the NoteBook widget.
圖像類型
tkinter.tix 模塊增加了:
-
pixmap capabilities to all tkinter.tix and tkinter widgets to create color images from XPM files.
-
Compound image types 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 to display a bitmap and a text string simultaneously in a Tk
Buttonwidget.
其他部件
class tkinter.tix.InputOnly
The InputOnly widgets are to accept inputs from the user, which can be done with the bind command (Unix only).
表單布局管理器
tkinter.tix 還額外提供了以下部件來增強 tkinter 的功能:
class tkinter.tix.Form
The Form geometry manager based on attachment rules for all Tk widgets.
Tix 命令
class tkinter.tix.tixCommand
The tix commands provide access to miscellaneous elements of Tix‘s internal state and the Tix application context. Most of the information manipulated by these methods pertains to the application as a whole, or to a screen or display, rather than to a particular window.
要查看當前的設置,通常的用法是:
from tkinter import tixroot = tix.Tk()print(root.tix_configure())
tixCommand.tix_configure(cnf=None, \*kw*)
查詢或修改 Tix 應用程序上下文的配置選項。 如果未指定任何選項,則返回包含所有選項的字典。 如果指定了不帶值的選項,則該方法返回描述指定選項的列表(如果未指定選項則此列表與所返回值對應的子列表相同)。 如果指定了一個或多個選項-值對,則該方法會將指定的選項修改為指定的值;在此情況下該方法將返回一個空字符串。 選項可以是配置選項中的任何一個。
tixCommand.tix_cget(option)
返回由 option 給出的配置選項的當前值。 選項可以是配置選項中的任何一個。
tixCommand.tix_getbitmap(name)
在某個位圖目錄中定位名稱為 name.xpm 或 name 的位圖文件(位圖目錄參見 tix_addbitmapdir() 方法)。 通過使用 tix_getbitmap(),你可以避免在你的應用程序中硬編碼位圖文件的路徑名。 執(zhí)行成功時,它返回位圖文件的完整路徑名,并帶有前綴字符 @。 返回值可被用于配置 Tk 和 Tix 部件的 bitmap 選項。
tixCommand.tix_addbitmapdir(directory)
Tix 維護了一個列表以供 tix_getimage() 和 tix_getbitmap() 方法在其中搜索圖像文件。 標準位圖目錄是 $TIX_LIBRARY/bitmaps。 tix_addbitmapdir() 方法向該列表添加了 directory。 通過使用此方法,應用程序的圖像文件也可使用 tix_getimage() 或 tix_getbitmap() 方法來定位。
tixCommand.tix_filedialog([dlgclass])
返回可在來自該應用程序的同不調用之間共享的選擇對話框。 此方法將在首次被調用時創(chuàng)建一個選擇對話框部件。 此后對 tix_filedialog() 的所有調用都將返回該對話框。 可以傳入一個字符串形式的可選形參 dlgclass 來指明所需的選擇對話框類型。 可用的選項有 tix, FileSelectDialog 或 tixExFileSelectDialog。
tixCommand.tix_getimage(self, name)
在某個位圖目錄(參見上文的 tix_addbitmapdir() 方法)中定位名為 name.xpm, name.xbm 或 name.ppm 的圖像文件。 如果存在多個同名文件(但擴展名不同),則會按照 X 顯示的深度選擇圖像類型:單色顯示選擇 xbm 圖像而彩色顯示則選擇彩色圖像。 通過使用 tix_getimage(),你可以避免在你的應用程序中硬編碼圖像文件的路徑名。 當執(zhí)行成功時,此方法將返回新創(chuàng)建圖像的名稱,它可被用于配置 Tk 和 Tix 部件的 image 選項。
tixCommand.tix_option_get(name)
獲取由 Tix 方案機制維護的選項。
tixCommand.tix_resetoptions(newScheme, newFontSet[, newScmPrio])
將 Tix 應用程序的方案與字體集分別重置為 newScheme 和 newFontSet。 這只會影響調用此方法之后創(chuàng)建的部件。 因此,最好是在 Tix 應用程序的任何部件被創(chuàng)建之前調用 resetoptions 方法。
可以給出可選的形參 newScmPrio 來重置由 Tix 方案所設置的 Tk 選項的優(yōu)先級。
由于 Tk 處理 X 選項數(shù)據庫的特別方式,在 Tix 被導入并初始化之后,將無法再使用 tix_config() 方法來重置顏色方案和字體集。 而必須要使用 tix_resetoptions() 方法。
新聞標題:創(chuàng)新互聯(lián)Python教程:tkinter.tix—-TK擴展包
網頁URL:http://fisionsoft.com.cn/article/cosphje.html


咨詢
建站咨詢
