ttk.Treeview

TTK的目的。

TreeView控件的呈现层次结构,用户可以使用鼠标动作来显示或隐藏结构的任何部分。

与术语“树”的关联是由于编程实践:树结构是一个常见的程序设计。严格地说,在一个TreeView控件显示的层次结构是一个森林:没有一个根,只是一个收集的顶级节点,每个可能包含二级节点,每个节点可以包含第三级,等等。

您可能已经遇到了这个特定的演示文稿作为浏览目录或文件夹层次结构的一种方式。整个层次结构显示像一个锯齿状的轮廓,其中每个目录是一个单独的行,并显示每个目录的子目录下面,缩进:

用户可以点击一个目录的图标崩溃(关闭)它,隐藏在它的所有项目。他们也可以再次点击图标来展开(打开)它,以便目录或文件夹中的项目被显示出来。

yòng用   户   可   以   diǎn点   击   一   个   目   录   de的   图   biāo标   bēng崩   kuì溃   (   guān关   闭   )   它   ,   yǐn隐   cáng藏   zài在   它   de的   suǒ所   yǒu有   xiàng项   目   。   他   men们   也   可   以   zài再   次   diǎn点   击   图   biāo标   lái来   zhǎn展   kāi开   (   打   kāi开   )   它   ,   以   biàn便   目   录   huò或   wén文   jiàn件   jiā夹   zhōng中   de的   xiàng项   目   bèi被   xiǎn显   shì示   chū出   lái来   。  

The Treeview widget generalizes this concept so that you can use it to display any hierarchical structure, and the reader can collapse or expand subtrees of this structure with the mouse.

的TreeView控件的推广这个概念,你可以用它来显示任何层次结构,和读者可以折叠或展开这一结构子树与鼠标。

de的   T   r   e   e   V   i   e   w   kòng控   jiàn件   de的   tuī推   guǎng广   zhè这   ge个   gài概   niàn念   ,   你   可   以   yòng用   它   lái来   xiǎn显   shì示   rèn任   何   céng层   次   jié结   gòu构   ,   和   读   zhě者   可   以   zhé折   dié叠   huò或   zhǎn展   kāi开   zhè这   一   jié结   gòu构   子   shù树   与   shǔ鼠   biāo标   。  

First, some definitions:

首先,一些定义:

shǒu首   xiān先   ,   一   xiē些   dìng定   义   :  

item

item

xiàng项   目  

One of the entities being displayed in the widget. For a file browser, an item might be either a directory or a file.

正在显示的部件中的一个实体。对于一个文件浏览器,一个项目可能是一个目录或一个文件。

zhèng正   zài在   xiǎn显   shì示   de的   部   jiàn件   zhōng中   de的   一   个   shí实   体   。   duì对   于   一   个   wén文   jiàn件   liú浏   lǎn览   器   ,   一   个   xiàng项   目   可   néng能   shì是   一   个   目   录   huò或   一   个   wén文   jiàn件   。  

Each item is associated with a textual label, and may also be associated with an image.

每个项目都与文本标签相关联的,也可以与图像相关联的。

měi每   个   xiàng项   目   dōu都   与   wén文   běn本   biāo标   qiān签   xiāng相   guān关   lián联   de的   ,   也   可   以   与   图   xiàng像   xiāng相   guān关   lián联   de的   。  

iid

IID

I   I   D  

Every item in the tree has a unique identifier string called the iid. You can supply the iid values yourself, or you can let ttk generate them.

在树的每一个项目都有一个唯一的标识符字符串称为IID。你们能提供的IID值你自己,或者你可以让这些生成。

zài在   shù树   de的   měi每   一   个   xiàng项   目   dōu都   yǒu有   一   个   wéi唯   一   de的   biāo标   shí识   符   字   符   chuàn串   chēng称   wéi为   I   I   D   。   你   men们   néng能   提   gōng供   de的   I   I   D   zhí值   你   自   己   ,   huò或   zhě者   你   可   以   ràng让   zhè这   xiē些   shēng生   chéng成   。  

child

child

xiǎo小   hái孩  

The items directly below a given item in a hierarchy. A directory, for example, may have two kinds of children: files and subdirectories.

在层次结构中的一个给定项目下的项目。例如,一个目录,,可能有两种孩子:文件和子目录。

zài在   céng层   次   jié结   gòu构   zhōng中   de的   一   个   gěi给   dìng定   xiàng项   目   xià下   de的   xiàng项   目   。   例   如   ,   一   个   目   录   ,   ,   可   néng能   yǒu有   liǎng两   zhǒng种   hái孩   zi子   :   wén文   jiàn件   和   子   目   录   。  

parent

parent

起   yuán源  

For a given item, if it is at the top of the hierarchy it is said to have no parent; if it is not at the top level, the parent is the item that contains it.

对于一个给定的项目,如果它是在层次结构的顶部,它被称为没有父;如果它不是在顶层,父是包含它的项目。

duì对   于   一   个   gěi给   dìng定   de的   xiàng项   目   ,   如   guǒ果   它   shì是   zài在   céng层   次   jié结   gòu构   de的   dǐng顶   部   ,   它   bèi被   chēng称   wéi为   méi没   yǒu有   父   ;   如   guǒ果   它   不   shì是   zài在   dǐng顶   céng层   ,   父   shì是   bāo包   hán含   它   de的   xiàng项   目   。  

ancestor

ancestor

祖   xiān先  

The ancestors of an item include its parent, its parent's parent, and so on up to the top level of the tree.

一个项目的祖先包括它的父母,它的父母的父母,所以在树的最高水平。

一   个   xiàng项   目   de的   祖   xiān先   bāo包   kuò括   它   de的   父   母   ,   它   de的   父   母   de的   父   母   ,   suǒ所   以   zài在   shù树   de的   zuì最   gāo高   shuǐ水   píng平   。  

visible

visible        

kàn看   de得   jiàn见   de的  

Top-level items are always visible. Otherwise, an item is visible only if all its ancestors are expanded.

顶层项目总是可见的。否则,只有当所有的祖先都被扩展时,一个项目是可见的。

dǐng顶   céng层   xiàng项   目   zǒng总   shì是   可   jiàn见   de的   。   fǒu否   则   ,   zhǐ只   yǒu有   dāng当   suǒ所   yǒu有   de的   祖   xiān先   dōu都   bèi被   kuò扩   zhǎn展   shí时   ,   一   个   xiàng项   目   shì是   可   jiàn见   de的   。  

descendant

descendant

hòu后   裔  

The descendants of an item include its children, its childrens' children, and so on. Another way of saying this is that the subtree of an item includes all its descendants.

一个项目的后代包括它的孩子,它的孩子的孩子,等等。另一种说法是,一个项目的子树包含所有它的后代。

一   个   xiàng项   目   de的   hòu后   dài代   bāo包   kuò括   它   de的   hái孩   zi子   ,   它   de的   hái孩   zi子   de的   hái孩   zi子   ,   děng等   děng等   。   lìng另   一   zhǒng种   shuō说   法   shì是   ,   一   个   xiàng项   目   de的   子   shù树   bāo包   hán含   suǒ所   yǒu有   它   de的   hòu后   dài代   。  

tag

tag

biāo标   qiān签  

Your program can associate one or more tag strings with each item. You can use these tags to control the appearance of an item. For example, you could tag directories with the tag 'd' and files with the tag 'f', and then specify that items with tag 'd' use a boldface font.

您的程序可以将一个或多个标记字符串与每个项目关联。您可以使用这些标签来控制项目的外观。例如,你可以使用标签的“D”和“F”文件的标签标签的目录,然后指定物品的标签“D”用黑体字体。

nín您   de的   chéng程   序   可   以   jiāng将   一   个   huò或   duō多   个   biāo标   记   字   符   chuàn串   与   měi每   个   xiàng项   目   guān关   lián联   。   nín您   可   以   shǐ使   yòng用   zhè这   xiē些   biāo标   qiān签   lái来   kòng控   zhì制   xiàng项   目   de的   wài外   guān观   。   例   如   ,   你   可   以   shǐ使   yòng用   biāo标   qiān签   de的   “   D   ”   和   “   F   ”   wén文   jiàn件   de的   biāo标   qiān签   biāo标   qiān签   de的   目   录   ,   rán然   hòu后   zhǐ指   dìng定   物   pǐn品   de的   biāo标   qiān签   “   D   ”   yòng用   hēi黑   体   字   体   。  

You may also associate events with tags, so that certain events will cause certain handlers to be called for all items that have that tag. For example, you could set up a file browser so that when a user clicks on a directory, the browser updated its contents to reflect the current file structure.

您也可以将事件与标签关联,以便某些事件将导致某些处理程序被调用具有该标记的所有项目。例如,您可以设置一个文件浏览器,以便当用户点击一个目录时,浏览器更新其内容以反映当前的文件结构。

nín您   也   可   以   jiāng将   shì事   jiàn件   与   biāo标   qiān签   guān关   lián联   ,   以   biàn便   mǒu某   xiē些   shì事   jiàn件   jiāng将   dǎo导   zhì致   mǒu某   xiē些   chǔ处   理   chéng程   序   bèi被   diào调   yòng用   具   yǒu有   gāi该   biāo标   记   de的   suǒ所   yǒu有   xiàng项   目   。   例   如   ,   nín您   可   以   shè设   zhì置   一   个   wén文   jiàn件   liú浏   lǎn览   器   ,   以   biàn便   dāng当   yòng用   户   diǎn点   击   一   个   目   录   shí时   ,   liú浏   lǎn览   器   gēng更   xīn新   其   nèi内   róng容   以   fǎn反   yìng映   dāng当   qián前   de的   wén文   jiàn件   jié结   gòu构   。  

Your Treeview widget will be structured with multiple columns. The first column, which we'll call the icon column, displays the icons that collapse or expand items. In the remaining columns, you may display whatever information you like.

你的TreeView控件的结构将与多个列。我们将称为“图标”列的第一列,显示折叠或展开项目的图标。在剩下的栏目中,你可以展示你喜欢的任何信息。

你   de的   T   r   e   e   V   i   e   w   kòng控   jiàn件   de的   jié结   gòu构   jiāng将   与   duō多   个   liè列   。   我   men们   jiāng将   chēng称   wéi为   “   图   biāo标   ”   liè列   de的   第   一   liè列   ,   xiǎn显   shì示   zhé折   dié叠   huò或   zhǎn展   kāi开   xiàng项   目   de的   图   biāo标   。   zài在   shèng剩   xià下   de的   lán栏   目   zhōng中   ,   你   可   以   zhǎn展   shì示   你   喜   huan欢   de的   rèn任   何   xìn信   息   。  

For example, a simple file browser widget might use two columns, with the directory icons in the first column and the directory or file name in the second columns. Or you might wish to display file sizes, permissions, and other related data in additional columns.

例如,一个简单的文件浏览器组件可能使用两个列,在第一列中的目录图标和第二列中的目录或文件名。或者您可能希望显示其他列的文件大小、权限和其他相关数据。

例   如   ,   一   个   jiǎn简   dān单   de的   wén文   jiàn件   liú浏   lǎn览   器   组   jiàn件   可   néng能   shǐ使   yòng用   liǎng两   个   liè列   ,   zài在   第   一   liè列   zhōng中   de的   目   录   图   biāo标   和   第   èr二   liè列   zhōng中   de的   目   录   huò或   wén文   jiàn件   míng名   。   huò或   zhě者   nín您   可   néng能   希   wàng望   xiǎn显   shì示   其   他   liè列   de的   wén文   jiàn件   大   xiǎo小   、   quán权   xiàn限   和   其   他   xiāng相   guān关   shù数   据   。  

The operations of the Treeview widget even allow you to use it as a tree editor. Your program can remove an entire subtree from its location in the main tree and then attach it later at an entirely different point.

在TreeView控件的操作,甚至允许你使用它作为一个树编辑。你的程序可以删除整个子树从它的位置在主树,然后将它之后在一个完全不同的角度。

zài在   T   r   e   e   V   i   e   w   kòng控   jiàn件   de的   cāo操   zuò作   ,   shèn甚   zhì至   yǔn允   许   你   shǐ使   yòng用   它   zuò作   wéi为   一   个   shù树   biān编   辑   。   你   de的   chéng程   序   可   以   shān删   chú除   zhěng整   个   子   shù树   cóng从   它   de的   wèi位   zhi置   zài在   zhǔ主   shù树   ,   rán然   hòu后   jiāng将   它   zhī之   hòu后   zài在   一   个   wán完   quán全   不   tóng同   de的   jiǎo角   度   。  

Here is the general procedure for setting up a Treeview widget.

这里是设置TreeView控件的一般程序。

zhè这   里   shì是   shè设   zhì置   T   r   e   e   V   i   e   w   kòng控   jiàn件   de的   一   bān般   chéng程   序   。  

1. Create the widget with the ttk.Treeview constructor. Use the columns keyword argument to specify the number of columns to be displayed and to assign symbolic names to each column.

1。创建TTK TreeView的构造函数的部件。使用列关键字参数来指定要显示的列数,并为每个列分配符号名。

1   。   chuàng创   jiàn建   T   T   K   T   r   e   e   V   i   e   w   de的   gòu构   zào造   hán函   shù数   de的   部   jiàn件   。   shǐ使   yòng用   liè列   guān关   jiàn键   字   cān参   shù数   lái来   zhǐ指   dìng定   yào要   xiǎn显   shì示   de的   liè列   shǔ数   ,   bìng并   wèi为   měi每   个   liè列   fēn分   pèi配   符   hào号   míng名   。  

2. Use the .column() and .heading() methods to set up column headings (if you want them) and configure column properties such as size and stretchability.

2。使用。column()和。heading()方法设置列标题(如果你想)和配置列属性如大小和拉伸性。

2   。   shǐ使   yòng用   。   c   o   l   u   m   n   (   )   和   。   h   e   a   d   i   n   g   (   )   fāng方   法   shè设   zhì置   liè列   biāo标   题   (   如   guǒ果   你   xiǎng想   )   和   pèi配   zhì置   liè列   shǔ属   xìng性   如   大   xiǎo小   和   拉   shēn伸   xìng性   。  

3. Starting with the top-level entries, use the .insert() method to populate the tree. Each call to this method adds one item to the tree. Use the open keyword argument of this method to specify whether the item is initially expanded or collapsed.

三.从顶层的条目,使用方法。insert()填充树。每个对该方法的调用将一个项目添加到树中。使用此方法的打开关键字参数来指定项目是否最初是扩展或折叠的。

sān三   .   cóng从   dǐng顶   céng层   de的   tiáo条   目   ,   shǐ使   yòng用   fāng方   法   。   i   n   s   e   r   t   (   )   tián填   chōng充   shù树   。   měi每   个   duì对   gāi该   fāng方   法   de的   diào调   yòng用   jiāng将   一   个   xiàng项   目   tiān添   jiā加   dào到   shù树   zhōng中   。   shǐ使   yòng用   此   fāng方   法   de的   打   kāi开   guān关   jiàn键   字   cān参   shù数   lái来   zhǐ指   dìng定   xiàng项   目   shì是   fǒu否   zuì最   chū初   shì是   kuò扩   zhǎn展   huò或   zhé折   dié叠   de的   。  

If you want to supply the iid value for this item, use the iid keyword argument. If you omit this argument, ttk will make one up and return it as the result of the .insert() method call.

如果你想为这个项目提供的ID值,使用IID关键字参数。如果省略此参数,将使一个TTK并返回它的结果。insert()方法调用。

如   guǒ果   你   xiǎng想   wèi为   zhè这   ge个   xiàng项   目   提   gōng供   de的   I   D   zhí值   ,   shǐ使   yòng用   I   I   D   guān关   jiàn键   字   cān参   shù数   。   如   guǒ果   shěng省   lvè略   此   cān参   shù数   ,   jiāng将   shǐ使   一   个   T   T   K   bìng并   fǎn返   huí回   它   de的   jié结   guǒ果   。   i   n   s   e   r   t   (   )   fāng方   法   diào调   yòng用   。  

Use the values keyword argument of this method to specify what should appear in each column of this item when it is visible.

使用此方法的值关键字参数指定在该项目的每个列中应出现的什么时,它是可见的。

shǐ使   yòng用   此   fāng方   法   de的   zhí值   guān关   jiàn键   字   cān参   shù数   zhǐ指   dìng定   zài在   gāi该   xiàng项   目   的   měi每   个   liè列   zhōng中   yīng应   chū出   xiàn现   de的   shén什   me么   shí时   ,   它   shì是   可   jiàn见   de的   。  

To create a Treeview widget within a given parent widget:

在一个给定的父控件创建一个TreeView控件:

w = ttk.Treeview(parent, option=value, ...)

构造函数返回新的TreeView控件。它的选项包括:

class_

当您创建这个小部件时,您可以提供一个小部件的名称。此名称可用于自定义小部件的外观;请参见第27节“标准外观”。一旦创建了小部件,则无法更改小部件的名称。

columns

列标识符字符串的序列。这些字符串在内部使用,以确定控件中的列。图标栏,其标识符总是“# 0”,包含折叠/展开的图标总是第一列。

liè列   biāo标   shí识   符   字   符   chuàn串   de的   序   liè列   。   zhè这   xiē些   字   符   chuàn串   zài在   nèi内   部   shǐ使   yòng用   ,   以   què确   dìng定   kòng控   jiàn件   zhōng中   de的   liè列   。   图   biāo标   lán栏   ,   其   biāo标   shí识   符   zǒng总   shì是   “   #   0   ”   ,   bāo包   hán含   zhé折   dié叠   /   zhǎn展   kāi开   de的   图   biāo标   zǒng总   shì是   第   一   liè列   。  

The columns you specify with the columns argument are in addition to the icon column.

您指定的列参数的列除了图标列之外。

nín您   zhǐ指   dìng定   de的   liè列   cān参   shù数   de的   liè列   chú除   le了   图   biāo标   liè列   zhī之   wài外   。  

For example, if you specified columns=('Name', 'Size'), three columns would appear in the widget: first the icon column, then two more columns whose internal identifiers are 'Name' and 'Size'.

例如,如果你指定的列=('name','大小'),三列将出现在窗口的图标:第一列,然后两柱内部标识符的名称和大小。

cursor

使用该选项指定鼠标光标的外观,当它在窗口;参见5.8节,“光标”。指定的默认值(一个空字符串)指定从父控件继承的光标。

displaycolumns

选择实际上显示的列,并确定它们的演示文稿的顺序。价值观可能:

xuǎn选   择   shí实   际   shang上   xiǎn显   shì示   de的   liè列   ,   bìng并   què确   dìng定   它   men们   de的   yǎn演   shì示   wén文   gǎo稿   de的   shùn顺   序   。   jià价   zhí值   guān观   可   néng能   :  

• '#all' to select all columns and display them in the order defined by the columns argument.

•”#所有选择所有列的列参数定义的顺序显示。

•   ”   #   suǒ所   yǒu有   xuǎn选   择   suǒ所   yǒu有   liè列   de的   liè列   cān参   shù数   dìng定   义   de的   shùn顺   序   xiǎn显   shì示   。  

• A list of column numbers (integer positions, counting from 0) or column identifiers from the columns argument.

A列数(整数的位置,从0计数)或列标识符从列参数列表。

A   liè列   shǔ数   (   zhěng整   shù数   de的   wèi位   zhi置   ,   cóng从   0   计   shù数   )   huò或   liè列   biāo标   shí识   符   cóng从   liè列   cān参   shù数   liè列   biǎo表   。  

For example, suppose you specify columns=('Name', 'Size', 'Date'). This means each call to the .insert() method will require an argument values=(name, size, date) to supply the values that will be displayed. Let's call this sequence the logical column sequence.

例如,假设你指定列=('name','大小','日')。这意味着每个电话。insert()方法需要一个参数值=(名称、大小、日期)提供的值将被显示。让我们将此序列称为“逻辑列”序列。

例   如   ,   jiǎ假   shè设   你   zhǐ指   dìng定   liè列   =   (   '   n   a   m   e   '   ,   '   大   xiǎo小   '   ,   '   日   '   )   。   zhè这   意   wèi味   zhe着   měi每   个   diàn电   huà话   。   i   n   s   e   r   t   (   )   fāng方   法   需   yào要   一   个   cān参   shù数   zhí值   =   (   míng名   chēng称   、   大   xiǎo小   、   日   期   )   提   gōng供   de的   zhí值   jiāng将   bèi被   xiǎn显   shì示   。   ràng让   我   men们   jiāng将   此   序   liè列   chēng称   wéi为   “   luó逻   辑   liè列   ”   序   liè列   。  

Further suppose that in the constructor you specify columns=(2,0). The physical column sequence, the columns that will actually appear in the widget, will be three: the icon column will be first, followed by the date column (index 2 in the logical column sequence), followed by the name column (logical column index 0). The size column will not appear.

进一步假设你指定列=构造函数(2,0)。物理列的顺序,将实际出现在小部件中的列,将是三:图标列将是第一个,然后是数据列(逻辑列序列中的索引2),然后是“名称”列(逻辑列索引0)。大小列将不会出现。

jìn进   一   步   jiǎ假   shè设   你   zhǐ指   dìng定   liè列   =   gòu构   zào造   hán函   shù数   (   2   ,   0   )   。   物   理   liè列   de的   shùn顺   序   ,   jiāng将   shí实   际   chū出   xiàn现   zài在   xiǎo小   部   jiàn件   zhōng中   de的   liè列   ,   jiāng将   shì是   sān三   :   图   biāo标   liè列   jiāng将   shì是   第   一   个   ,   rán然   hòu后   shì是   shù数   据   liè列   (   luó逻   辑   liè列   序   liè列   zhōng中   de的   suǒ索   yǐn引   2   )   ,   rán然   hòu后   shì是   “   míng名   chēng称   ”   liè列   (   luó逻   辑   liè列   suǒ索   yǐn引   0   )   。   大   xiǎo小   liè列   jiāng将   不   huì会   chū出   xiàn现   。  

You could get the same effect by specifying column identifiers instead of logical column positions: columns=('Date', 'Name').

你可以通过指定列的标识符,而不是逻辑列位置得到同样的效果:柱=('date ','名')。

height

使用此参数可以将额外的空间放在小部件内部的内容周围。您可以提供一个单一的维度或一个高达四个维度的序列,根据本表解释:

Values givenLeftTopRightBottom
aaaaa
a babab
a b cacbc
a b c dabcd

 selectmode

此选项可以控制用户允许使用鼠标选择什么。可以值:

selectmode='browse'                                                  The user may select only one item at a time.                        
selectmode='extended'                                                  The user may select multiple items at once.                        
selectmode='none'                        

                          The user cannot select items with the mouse.

 show

抑制标签在每一列的顶部,指定显示=‘树’。默认是显示列标签。

style

使用此选项可以指定一个自定义控件样式名称;参见47节,“定制和创建TTK的主题和风格”。

takefocus

使用这个选项来指定一个小部件是否被访问在焦点遍历;见第53节,“焦点:路由键盘输入”。指定takefocus =真正的如果你想去接受焦点;指定takefocus =如果控件不接受焦点错误。默认值为空字符串;默认情况下,控件获得焦点的控件做的TTK。

这里有一个TreeView控件的使用方法。

zhè这   里   yǒu有   一   个   T   r   e   e   V   i   e   w   kòng控   jiàn件   de的   shǐ使   yòng用   fāng方   法   。  

.bbox(item, column=None)

.bbox(item,column=None)

。   B   B   O   X   (   xiàng项   目   ,   liè列   =   méi没   yǒu有   )  

For the item with iid item, if the item is currently visible, this method returns a tuple (x, y, w, h), where (x, y) are the coordinates of the upper left corner of that item relative to the widget, and w and h are the width and height of the item in pixels. If the item is not visible, the method returns an empty string.

该项目的项目,如果该项目是目前可见的,此方法返回一个元组(X,Y,W,H),其中(x,y)是该项目的左上角的坐标相对于控件,和W和H是该项目的宽度和像素高度。如果该项目是不可见的,该方法返回一个空字符串。

gāi该   xiàng项   目   的   xiàng项   目   ,   如   guǒ果   gāi该   xiàng项   目   shì是   目   qián前   可   jiàn见   de的   ,   此   fāng方   法   fǎn返   huí回   一   个   yuán元   组   (   X   ,   Y   ,   W   ,   H   )   ,   其   zhōng中   (   x   ,   y   )   shì是   gāi该   xiàng项   目   的   zuǒ左   shàng上   jiǎo角   de的   zuò坐   biāo标   xiāng相   duì对   于   kòng控   jiàn件   ,   和   W   和   H   shì是   gāi该   xiàng项   目   的   kuān宽   度   和   xiàng像   素   gāo高   度   。   如   guǒ果   gāi该   xiàng项   目   shì是   不   可   jiàn见   de的   ,   gāi该   fāng方   法   fǎn返   huí回   一   个   kōng空   字   符   chuàn串   。  

If the optional column argument is omitted, you get the bounding box of the entire row. To get the bounding box of one specific column of the item's row, use column=C where C is either the integer index of the column or its column identifier.

如果省略了可选的列参数,则将得到整个行的包围盒。要得到项目行的一个特定列的包围框,使用列= C,其中C是列的整数索引或它的列标识符。

如   guǒ果   shěng省   lvè略   le了   可   xuǎn选   de的   liè列   cān参   shù数   ,   则   jiāng将   得   dào到   zhěng整   个   xíng行   de的   bāo包   wéi围   盒   。   yào要   得   dào到   xiàng项   目   xíng行   de的   一   个   特   dìng定   liè列   de的   bāo包   wéi围   kuàng框   ,   shǐ使   yòng用   liè列   =   C   ,   其   zhōng中   C   shì是   liè列   de的   zhěng整   shù数   suǒ索   yǐn引   huò或   它   de的   liè列   biāo标   shí识   符   。  

.column(cid, option=None, **kw)

.column(cid, option=None, **kw)        

。   zhù柱   (   C   I   D   ,   xuǎn选   xiàng项   =   无   ,   ×   ×   qiān千   瓦   )  

This method configures the appearance of the logical column specified by cid, which may be either a column index or a column identifier. To configure the icon column, use a cid value of '#0'.

该方法配置指定的CID的逻辑列的外观,它可以是一个列的索引或列标识。配置图标栏,使用CID值“0”#。

gāi该   fāng方   法   pèi配   zhì置   zhǐ指   dìng定   de的   C   I   D   de的   luó逻   辑   liè列   de的   wài外   guān观   ,   它   可   以   shì是   一   个   liè列   de的   suǒ索   yǐn引   huò或   liè列   biāo标   shí识   。   pèi配   zhì置   图   biāo标   lán栏   ,   shǐ使   yòng用   C   I   D   zhí值   “   0   ”   #   。  

Each column in a Treeview widget has its own set of options from this table:

在TreeView控件的每个列都有其选择自己从这个表:

anchor                                      The anchor that                    specifies where to position the content of the                    column.  The default value is 'w'.                  
id                                      The column name.  This option is read-only and                    set when the constructor is called.                  
minwidth                                      Minimum width of the column in pixels; the default                    value is 20.                  
stretch                                      If this option is True, the                    column's width will be adjusted when the widget is                    resized.  The default setting is 1.                  
width                                      Initial width of the column in pixels; the default                    is 200.

 如果提供了没有选项值或任何其他关键字参数,则该方法将返回指定列的列选项的字典。

如   guǒ果   提   gōng供   le了   méi没   yǒu有   xuǎn选   xiàng项   zhí值   huò或   rèn任   何   其   他   guān关   jiàn键   字   cān参   shù数   ,   则   gāi该   fāng方   法   jiāng将   fǎn返   huí回   zhǐ指   dìng定   liè列   de的   liè列   xuǎn选   xiàng项   de的   字   diǎn典   。  

• To interrogate the current value of an option named X , use an argument option=X.

•审问的一个选项,命名为x的当前值,使用一个参数选项= x。

•   shěn审   wèn问   de的   一   个   xuǎn选   xiàng项   ,   mìng命   míng名   wéi为   x   de的   dāng当   qián前   zhí值   ,   shǐ使   yòng用   一   个   cān参   shù数   xuǎn选   xiàng项   =   x   。  

• To set one or more column options, you may pass keyword arguments using the option names shown above, e.g., anchor=tk.CENTER to center the column contents.

•设置一个或多个列的选项,你可以通过关键字参数使用上面显示的选项名称如锚= tk.center中心栏目内容。

.delete(*items)        

参数是IID值。在有匹配的IID值部件的所有项目都被摧毁了,连同他们的后代。

.detach(*items)

参数是IID值。在有匹配的IID值的控件的所有物品都是从可见的部件拆下,连同他们的后代。

cān参   shù数   shì是   I   I   D   zhí值   。   zài在   yǒu有   匹   pèi配   de的   I   I   D   zhí值   de的   kòng控   jiàn件   de的   suǒ所   yǒu有   物   pǐn品   dōu都   shì是   cóng从   可   jiàn见   de的   部   jiàn件   chāi拆   xià下   ,   lián连   tóng同   他   men们   de的   hòu后   dài代   。  

The items are not destroyed. You may reattach them to the visible tree using the .move() method described below.

项目没有被销毁。你可以将它们用可见树move()下面描述的方法。

.exists(iid)        

返回true,如果存在一个项目中的控件与给定的IID,否则。如果一个项目不可见因为它被删除的。detach()方法,它仍然被认为是为这个目的而存在。exists()方法。

.focus([iid])        

如果你不为这个方法提供了一种说法,你回来或者物品的IID当前具有焦点,或“如果没有项目有焦点。

如   guǒ果   你   不   wèi为   zhè这   ge个   fāng方   法   提   gōng供   le了   一   zhǒng种   shuō说   法   ,   你   huí回   lái来   huò或   zhě者   物   pǐn品   de的   I   I   D   dāng当   qián前   具   yǒu有   jiāo焦   diǎn点   ,   huò或   “   如   guǒ果   méi没   yǒu有   xiàng项   目   yǒu有   jiāo焦   diǎn点   。  

You can give focus to an item by passing its iid as the argument to this method.

你可以通过其IID作为参数传递给这个方法一个项目给予重点。

.get_children([item])        

返回一个元组的儿童项目的项目参数指定的ID值。如果省略该参数,你会得到一个元组包含顶级项目的IID值。

fǎn返   huí回   一   个   yuán元   组   de的   ér儿   tóng童   xiàng项   目   de的   xiàng项   目   cān参   shù数   zhǐ指   dìng定   de的   I   D   zhí值   。   如   guǒ果   shěng省   lvè略   gāi该   cān参   shù数   ,   你   huì会   得   dào到   一   个   yuán元   组   bāo包   hán含   dǐng顶   级   xiàng项   目   de的   I   I   D   zhí值   。  

.heading(cid, option=None, **kw)

。标题(CID,选项=无,××千瓦)

。   biāo标   题   (   C   I   D   ,   xuǎn选   xiàng项   =   无   ,   ×   ×   qiān千   瓦   )  

Use this method to configure the column heading that appears at the top of the widget for the column specified by cid, which may be either a column index or a column identifier. Use a cid argument value of '#0' to configure the heading over the icon column.

使用此方法可以配置在指定的CID柱部件的顶部显示的列标题,可以是一个列的索引或列标识。使用CID参数值“0”#配置标题在图标栏。

shǐ使   yòng用   此   fāng方   法   可   以   pèi配   zhì置   zài在   zhǐ指   dìng定   de的   C   I   D   zhù柱   部   jiàn件   de的   dǐng顶   部   xiǎn显   shì示   de的   liè列   biāo标   题   ,   可   以   shì是   一   个   liè列   de的   suǒ索   yǐn引   huò或   liè列   biāo标   shí识   。   shǐ使   yòng用   C   I   D   cān参   shù数   zhí值   “   0   ”   #   pèi配   zhì置   biāo标   题   zài在   图   biāo标   lán栏   。  

Each heading has its own set of options with these names and values:

每个标题都有自己的一套选项,这些名称和值:

anchor                                      An anchor that specifies how the heading is                    aligned within the column; see Section 5.5, “Anchors”.  The default value is tk.W.                  
command                                      A procedure to be called when the user clicks on                    this column heading.                  
image                                      To present a graphic in the column heading (either                    with or instead of a text heading), set this                    option to an image, as specified in Section 5.9, “Images”.                  
text                                      The text that you want to appear in the column                    heading.

 如果您提供没有关键字参数,该方法将返回一个显示列标题选项当前设置的字典。

如   guǒ果   nín您   提   gōng供   méi没   yǒu有   guān关   jiàn键   字   cān参   shù数   ,   gāi该   fāng方   法   jiāng将   fǎn返   huí回   一   个   xiǎn显   shì示   liè列   biāo标   题   xuǎn选   xiàng项   dāng当   qián前   shè设   zhì置   de的   字   diǎn典   。  

• To interrogate the current value of some heading option X, use an argument of the form option=X; the method will return the current value of that option.

•审问一些标题选项当前x的值,使用表格选项= x参数;该方法将返回该选项的当前值。

•   shěn审   wèn问   一   xiē些   biāo标   题   xuǎn选   xiàng项   dāng当   qián前   x   de的   zhí值   ,   shǐ使   yòng用   biǎo表   格   xuǎn选   xiàng项   =   x   cān参   shù数   ;   gāi该   fāng方   法   jiāng将   fǎn返   huí回   gāi该   xuǎn选   xiàng项   de的   dāng当   qián前   zhí值   。  

• You can set one or more heading options by supplying them as keyword arguments such as “anchor=tk.CENTER”.

•可以设置一个或多个标题的选项提供给他们作为关键字参数如“anchor=tk.CENTER”.

.identify_column(x)        

给定一个X坐标,此方法返回一个字符串的形式# N标识包含x坐标列。

gěi给   dìng定   一   个   X   zuò坐   biāo标   ,   此   fāng方   法   fǎn返   huí回   一   个   字   符   chuàn串   de的   xíng形   shì式   #   N   biāo标   shí识   bāo包   hán含   x   zuò坐   biāo标   liè列   。  

Assuming that the icon column is displayed, the value of n is 0 for the icon column; 1 for the second physical column; 2 for the third physical column; and so on. Recall that the physical column number may be different from the logical column number in cases where you have rearranged them using the displaycolumns argument to the Treeview constructor.

假设显示图标列,n的值为图标列的0;第二个物理列的2;第三个物理列的1;等等。记得,物理列数可能不同于逻辑列数的情况下,你将使用displaycolumns TreeView构造函数参数。

jiǎ假   shè设   xiǎn显   shì示   图   biāo标   liè列   ,   n   de的   zhí值   wèi为   图   biāo标   liè列   de的   0   ;   第   èr二   个   物   理   liè列   de的   2   ;   第   sān三   个   物   理   liè列   de的   1   ;   děng等   děng等   。   记   de得   ,   物   理   liè列   shǔ数   可   néng能   不   tóng同   于   luó逻   辑   liè列   shǔ数   de的   qíng情   kuàng况   xià下   ,   你   jiāng将   shǐ使   yòng用   d   i   s   p   l   a   y   c   o   l   u   m   n   s   T   r   e   e   V   i   e   w   gòu构   zào造   hán函   shù数   cān参   shù数   。  

If the icon column is not displayed, the value of n is 1 for the first physical column, 2 for the second, and so on.

如果不显示图标列,则N的值为第一个物理列的2,第二个物理列的1,等等。

.identify_element(xy)        

返回相对于小部件的位置(X,Y)的元素的名称,或“如果没有出现在该位置上的元素”。元素名称在50节中讨论,“TTK元层”。

.identify_region(x,           y))

由于给定一个点相对于小部件的坐标,该方法返回一个字符串,该字符串表示该控件的一部分包含了该点的内容。返回值可能包括:

'nothing'                                      The point is not within a functional part of the                    widget.                  
'heading'                                      The point is within one of the column headings.                  
'separator'                                      The point is located within the column headings                    row, but on the separator between columns.  Use                    the .identify_column() method to                    determine which column is located just to the                    left of this separator.                  
'tree'                                      The point is located within the icon column.                  
'cell'                                      The point is located within an item row but not                    within the icon column.

 .identify_row(y)        

如果坐标内的项目之一,此方法返回该项的IID。如果该垂直坐标不在项目中,该方法将返回一个空字符串。

.index(iid)        

此方法返回的项的索引与指定其母相对独立,从零。

.set_children(item,          *newChildren)        

用这种方法来改变其IID是项项目子项的设置。新建的参数是一个字符串序列IID。任何当前儿童项目不新建删除。

.insert(parent,           index, iid=None, **kw)        

该方法将新项添加到树中,并返回该项的ID值。争论:

parent                                      To insert a new top-level item, make this argument                    an empty string.  To insert a new item as a child                    of an existing item, make this argument the parent                    item's iid.                  
index                                      This argument specifies the position among this                    parent's children where you want the new item to                    be added.  For example, to insert the item as                    the new first child, use a value of zero; to                    insert it after the parent's first child, use a                    value of 1; and so on.  To add the new item as                    the last child of the parent, make this argument's                    value 'end'.                                      
iid                                      You may supply an iid for the item as a string                    value.  If you don't supply an iid, one will be                    generated automatically and returned by the                    method.

 您也可以为该方法指定多个项目选项作为关键字参数。

image                                      You may display an image just to the right of the                    icon for this item's row by providing an image=I                    argument, where I is an image as specified                    in Section 5.9, “Images”.                  
open                                      This option specifies whether this item will be                    open initially.  If you supply open=False, this item will be closed.  If                    you supply open=True, the item's                    children will be visible whenever the item itself                    is visible.  The default value is False.                  
tags                                      You may supply one or more tag strings to be                    associated with this item.  The value may be                    either a single string or a sequence of strings.                  
text                                      You may supply text to be displayed within the                    icon column of this item.  If given, this text                    will appear just to the right of the icon, and                    also to the right of the image if provided.                  
values                                      This argument supplies the data items to be                    displayed in each column of the item.  The values                    are supplied in logical column order.  If too few                    values are supplied, the remaining columns will be                    blank in this item; if too many values are                    supplied, the extras will be discarded.

 .item(iid[, option[, **kw]])        

用这种方法来设置或检索选项指定IID项目内。参阅。insert()方法为项目选择的名字。

yòng用   zhè这   zhǒng种   fāng方   法   lái来   shè设   zhì置   huò或   jiǎn检   suǒ索   xuǎn选   xiàng项   zhǐ指   dìng定   I   I   D   xiàng项   目   nèi内   。   cān参   yuè阅   。   i   n   s   e   r   t   (   )   fāng方   法   wèi为   xiàng项   目   xuǎn选   择   de的   míng名   zi字   。  

With no arguments, it returns a dictionary whose keys are the option names and the corresponding values are the settings of those options. To retrieve the value of a given option, pass the option's name as its second argument. To set one or more options, pass them as keyword arguments to the method.

没有参数,它返回一个字典,它的键是选项名称,相应的值是这些选项的设置。要检索一个给定选项的值,将该选项的名称传递给它的第二个参数。要设置一个或多个选项,将它们作为关键字参数传递给方法。

.move(iid, parent, index)        

将指定的值由IID位置索引父所指定的项目项下。家长和指标参数相同的参数的方法。index()。

.next(iid)        

如果指定IID的项目不是其父亲的最后一个孩子,这个方法返回以下孩子的IID;如果是其父亲的最后一个孩子,这个方法将返回一个空字符串。如果指定的项目是一个顶级项目,方法返回下一个顶级项目的IID,或空字符串,如果指定的项目是最后的顶级项目。

.parent(iid)        

如果指定IID的项目是一个顶级项目,此方法将返回一个空字符串;否则返回的IID,项母。

.prev(iid)        

如果指定IID的项目并不是其父母的第一个孩子,这个方法返回之前的孩子的IID;否则返回一个空字符串。如果指定的项目是一个顶级项目,此方法返回之前的顶级项目的IID,或空字符串,如果是第一个顶级项目。

.see(iid)        

这种方法确保指定的IID项目是可见的。关闭的任何一的祖先都是开放的。Widget是滚动,如果有必要,使项目出现。

.selection_add(items)

除了已选择的任何项目外,还添加了指定的项目。参数可以是一个单一的IID或一个序列的系统。

.selection_remove(items)        

取消任何项目的指定参数,这可能是一个单一的IID或一个序列的系统。

.selection_set(items)        

只有指定的项将被选中;如果其他项目进行之前,他们会选择。

.selection_toggle(items)        

参数可以是一个单一的IID或一个序列的系统。每个项目指定的参数,如果它被选中,取消它;如果它被选中,选择它。

.set(iid, column=None,          value=None)        

使用此方法检索或设置列值的项指定IID。用一个参数,方法返回一个字典:键是列标识符,而每个相关的值都是在相应的列中的文本。

shǐ使   yòng用   此   fāng方   法   jiǎn检   suǒ索   huò或   shè设   zhì置   liè列   zhí值   de的   xiàng项   zhǐ指   dìng定   I   I   D   。   yòng用   一   个   cān参   shù数   ,   fāng方   法   fǎn返   huí回   一   个   字   diǎn典   :   jiàn键   shì是   liè列   biāo标   shí识   符   ,   ér而   měi每   个   xiāng相   guān关   de的   zhí值   dōu都   shì是   zài在   xiāng相   yìng应   de的   liè列   zhōng中   de的   wén文   běn本   。  

With two arguments, the method returns the data value from the column of the selected item whose column identifier is the column argument. With three arguments, the item's value for the specified column is set to the third argument.

有两个参数,方法将从所选项目的列返回数据值,其列标识符为列参数。有了三个参数,指定的列的值将被设置为第三个参数。

.tag_bind(tagName,          sequence=None, callback=None)        

该方法将由回调参数所设定的标签标签名指定事件处理程序。序列和回调参数相同的序列和功能参数。()方法在26节中描述的,“通用部件的方法”。

.tag_configure(tagName,          option=None, **kw)        

这种方法可以询问或设置影响所有的物品都有标签,标签名的外观选项。标签选项包括:

'background'                                      The background color.                  
'font'                                      The text font.                  
'foreground'                                      The foreground color.                  
'image'                                      An image to be                    displayed in items with the given tag.

 当调用一个参数时,它返回当前标记选项的字典。要返回一个特定选项x的值,使用X作为第二个参数。

dāng当   diào调   yòng用   一   个   cān参   shù数   shí时   ,   它   fǎn返   huí回   dāng当   qián前   biāo标   记   xuǎn选   xiàng项   de的   字   diǎn典   。   yào要   fǎn返   huí回   一   个   特   dìng定   xuǎn选   xiàng项   x   de的   zhí值   ,   shǐ使   yòng用   X   zuò作   wéi为   第   èr二   个   cān参   shù数   。  

To set one or more options, use keyword arguments such as foreground='red'.

设置一个或多个选项,使用关键字参数例如前景='red'

.tag_has(tagName[,           iid])        

用一个参数调用,该方法返回一个带有标签的标签名的所有项目的IID值列表。如果你提供一个IID作为第二个参数,该方法返回true,如果有标签的标签名,IID的项目,否则为假。

.xview(*args)

这是用于连接水平滚动条滚动部件的常用方法。有关详细信息,请参见第22.1节,“滚动条命令回调”。

.yview(*args)        

这是用于连接垂直滚动条滚动部件的常用方法。有关详细信息,请参见第22.1节,“滚动条命令回调”。

转载于:https://www.cnblogs.com/wumac/p/5841875.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值