TTK的目的。
TreeView控件的呈現層次結構,用戶可以使用鼠標動作來顯示或隱藏結構的任何部分。
與術語“樹”的關聯是由於編程實踐:樹結構是一個常見的程序設計。嚴格地說,在一個TreeView控件顯示的層次結構是一個森林:沒有一個根,只是一個收集的頂級節點,每個可能包含二級節點,每個節點可以包含第三級,等等。
您可能已經遇到了這個特定的演示文稿作為瀏覽目錄或文件夾層次結構的一種方式。整個層次結構顯示像一個鋸齒狀的輪廓,其中每個目錄是一個單獨的行,並顯示每個目錄的子目錄下面,縮進:

用戶可以點擊一個目錄的圖標崩潰(關閉)它,隱藏在它的所有項目。他們也可以再次點擊圖標來展開(打開)它,以便目錄或文件夾中的項目被顯示出來。
yòng用 hù戶 kě可 yǐ以 diǎn點 jī擊 yī一 gè個 mù目 lù錄 de的 tú圖 biāo標 bēng崩 kuì潰 ( guān關 bì閉 ) tā它 , yǐn隱 cáng藏 zài在 tā它 de的 suǒ所 yǒu有 xiàng項 mù目 。 tā他 men們 yě也 kě可 yǐ以 zài再 cì次 diǎn點 jī擊 tú圖 biāo標 lái來 zhǎn展 kāi開 ( dǎ打 kāi開 ) tā它 , yǐ以 biàn便 mù目 lù錄 huò或 wén文 jiàn件 jiā夾 zhōng中 de的 xiàng項 mù目 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念 , nǐ你 kě可 yǐ以 yòng用 tā它 lái來 xiǎn顯 shì示 rèn任 hé何 céng層 cì次 jié結 gòu構 , hé和 dú讀 zhě者 kě可 yǐ以 zhé折 dié疊 huò或 zhǎn展 kāi開 zhè這 yī一 jié結 gòu構 zǐ子 shù樹 yǔ與 shǔ鼠 biāo標 。
First, some definitions:
首先,一些定義:
shǒu首 xiān先 , yī一 xiē些 dìng定 yì義 :
item
item
xiàng項 mù目
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的 bù部 jiàn件 zhōng中 de的 yī一 gè個 shí實 tǐ體 。 duì對 yú於 yī一 gè個 wén文 jiàn件 liú瀏 lǎn覽 qì器 , yī一 gè個 xiàng項 mù目 kě可 néng能 shì是 yī一 gè個 mù目 lù錄 huò或 yī一 gè個 wén文 jiàn件 。
Each item is associated with a textual label, and may also be associated with an image.
每個項目都與文本標簽相關聯的,也可以與圖像相關聯的。
měi每 gè個 xiàng項 mù目 dōu都 yǔ與 wén文 běn本 biāo標 qiān簽 xiāng相 guān關 lián聯 de的 , yě也 kě可 yǐ以 yǔ與 tú圖 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每 yī一 gè個 xiàng項 mù目 dōu都 yǒu有 yī一 gè個 wéi唯 yī一 de的 biāo標 shí識 fú符 zì字 fú符 chuàn串 chēng稱 wéi為 I I D 。 nǐ你 men們 néng能 tí提 gōng供 de的 I I D zhí值 nǐ你 zì自 jǐ己 , huò或 zhě者 nǐ你 kě可 yǐ以 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層 cì次 jié結 gòu構 zhōng中 de的 yī一 gè個 gěi給 dìng定 xiàng項 mù目 xià下 de的 xiàng項 mù目 。 lì例 rú如 , yī一 gè個 mù目 lù錄 , , kě可 néng能 yǒu有 liǎng兩 zhǒng種 hái孩 zi子 : wén文 jiàn件 hé和 zǐ子 mù目 lù錄 。
parent
parent
qǐ起 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ì對 yú於 yī一 gè個 gěi給 dìng定 de的 xiàng項 mù目 , rú如 guǒ果 tā它 shì是 zài在 céng層 cì次 jié結 gòu構 de的 dǐng頂 bù部 , tā它 bèi被 chēng稱 wéi為 méi沒 yǒu有 fù父 ; rú如 guǒ果 tā它 bù不 shì是 zài在 dǐng頂 céng層 , fù父 shì是 bāo包 hán含 tā它 de的 xiàng項 mù目 。
ancestor
ancestor
zǔ祖 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.
一個項目的祖先包括它的父母,它的父母的父母,所以在樹的最高水平。
yī一 gè個 xiàng項 mù目 de的 zǔ祖 xiān先 bāo包 kuò括 tā它 de的 fù父 mǔ母 , tā它 de的 fù父 mǔ母 de的 fù父 mǔ母 , suǒ所 yǐ以 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項 mù目 zǒng總 shì是 kě可 jiàn見 de的 。 fǒu否 zé則 , zhǐ只 yǒu有 dāng當 suǒ所 yǒu有 de的 zǔ祖 xiān先 dōu都 bèi被 kuò擴 zhǎn展 shí時 , yī一 gè個 xiàng項 mù目 shì是 kě可 jiàn見 de的 。
descendant
descendant
hòu后 yì裔
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.
一個項目的后代包括它的孩子,它的孩子的孩子,等等。另一種說法是,一個項目的子樹包含所有它的后代。
yī一 gè個 xiàng項 mù目 de的 hòu后 dài代 bāo包 kuò括 tā它 de的 hái孩 zi子 , tā它 de的 hái孩 zi子 de的 hái孩 zi子 , děng等 děng等 。 lìng另 yī一 zhǒng種 shuō說 fǎ法 shì是 , yī一 gè個 xiàng項 mù目 de的 zǐ子 shù樹 bāo包 hán含 suǒ所 yǒu有 tā它 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程 xù序 kě可 yǐ以 jiāng將 yī一 gè個 huò或 duō多 gè個 biāo標 jì記 zì字 fú符 chuàn串 yǔ與 měi每 gè個 xiàng項 mù目 guān關 lián聯 。 nín您 kě可 yǐ以 shǐ使 yòng用 zhè這 xiē些 biāo標 qiān簽 lái來 kòng控 zhì制 xiàng項 mù目 de的 wài外 guān觀 。 lì例 rú如 , nǐ你 kě可 yǐ以 shǐ使 yòng用 biāo標 qiān簽 de的 “ D ” hé和 “ F ” wén文 jiàn件 de的 biāo標 qiān簽 biāo標 qiān簽 de的 mù目 lù錄 , rán然 hòu后 zhǐ指 dìng定 wù物 pǐn品 de的 biāo標 qiān簽 “ D ” yòng用 hēi黑 tǐ體 zì字 tǐ體 。
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您 yě也 kě可 yǐ以 jiāng將 shì事 jiàn件 yǔ與 biāo標 qiān簽 guān關 lián聯 , yǐ以 biàn便 mǒu某 xiē些 shì事 jiàn件 jiāng將 dǎo導 zhì致 mǒu某 xiē些 chǔ處 lǐ理 chéng程 xù序 bèi被 diào調 yòng用 jù具 yǒu有 gāi該 biāo標 jì記 de的 suǒ所 yǒu有 xiàng項 mù目 。 lì例 rú如 , nín您 kě可 yǐ以 shè設 zhì置 yī一 gè個 wén文 jiàn件 liú瀏 lǎn覽 qì器 , yǐ以 biàn便 dāng當 yòng用 hù戶 diǎn點 jī擊 yī一 gè個 mù目 lù錄 shí時 , liú瀏 lǎn覽 qì器 gēng更 xīn新 qí其 nèi內 róng容 yǐ以 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控件的結構將與多個列。我們將稱為“圖標”列的第一列,顯示折疊或展開項目的圖標。在剩下的欄目中,你可以展示你喜歡的任何信息。
nǐ你 de的 T r e e V i e w kòng控 jiàn件 de的 jié結 gòu構 jiāng將 yǔ與 duō多 gè個 liè列 。 wǒ我 men們 jiāng將 chēng稱 wéi為 “ tú圖 biāo標 ” liè列 de的 dì第 yī一 liè列 , xiǎn顯 shì示 zhé折 dié疊 huò或 zhǎn展 kāi開 xiàng項 mù目 de的 tú圖 biāo標 。 zài在 shèng剩 xià下 de的 lán欄 mù目 zhōng中 , nǐ你 kě可 yǐ以 zhǎn展 shì示 nǐ你 xǐ喜 huan歡 de的 rèn任 hé何 xìn信 xī息 。
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.
例如,一個簡單的文件瀏覽器組件可能使用兩個列,在第一列中的目錄圖標和第二列中的目錄或文件名。或者您可能希望顯示其他列的文件大小、權限和其他相關數據。
lì例 rú如 , yī一 gè個 jiǎn簡 dān單 de的 wén文 jiàn件 liú瀏 lǎn覽 qì器 zǔ組 jiàn件 kě可 néng能 shǐ使 yòng用 liǎng兩 gè個 liè列 , zài在 dì第 yī一 liè列 zhōng中 de的 mù目 lù錄 tú圖 biāo標 hé和 dì第 èr二 liè列 zhōng中 de的 mù目 lù錄 huò或 wén文 jiàn件 míng名 。 huò或 zhě者 nín您 kě可 néng能 xī希 wàng望 xiǎn顯 shì示 qí其 tā他 liè列 de的 wén文 jiàn件 dà大 xiǎo小 、 quán權 xiàn限 hé和 qí其 tā他 xiāng相 guān關 shù數 jù據 。
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允 xǔ許 nǐ你 shǐ使 yòng用 tā它 zuò作 wéi為 yī一 gè個 shù樹 biān編 jí輯 。 nǐ你 de的 chéng程 xù序 kě可 yǐ以 shān刪 chú除 zhěng整 gè個 zǐ子 shù樹 cóng從 tā它 de的 wèi位 zhi置 zài在 zhǔ主 shù樹 , rán然 hòu后 jiāng將 tā它 zhī之 hòu后 zài在 yī一 gè個 wán完 quán全 bù不 tóng同 de的 jiǎo角 dù度 。
Here is the general procedure for setting up a Treeview widget.
這里是設置TreeView控件的一般程序。
zhè這 lǐ里 shì是 shè設 zhì置 T r e e V i e w kòng控 jiàn件 de的 yī一 bān般 chéng程 xù序 。
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的 bù部 jiàn件 。 shǐ使 yòng用 liè列 guān關 jiàn鍵 zì字 cān參 shù數 lái來 zhǐ指 dìng定 yào要 xiǎn顯 shì示 de的 liè列 shǔ數 , bìng並 wèi為 měi每 gè個 liè列 fēn分 pèi配 fú符 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é和 。 h e a d i n g ( ) fāng方 fǎ法 shè設 zhì置 liè列 biāo標 tí題 ( rú如 guǒ果 nǐ你 xiǎng想 ) hé和 pèi配 zhì置 liè列 shǔ屬 xìng性 rú如 dà大 xiǎo小 hé和 lā拉 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條 mù目 , shǐ使 yòng用 fāng方 fǎ法 。 i n s e r t ( ) tián填 chōng充 shù樹 。 měi每 gè個 duì對 gāi該 fāng方 fǎ法 de的 diào調 yòng用 jiāng將 yī一 gè個 xiàng項 mù目 tiān添 jiā加 dào到 shù樹 zhōng中 。 shǐ使 yòng用 cǐ此 fāng方 fǎ法 de的 dǎ打 kāi開 guān關 jiàn鍵 zì字 cān參 shù數 lái來 zhǐ指 dìng定 xiàng項 mù目 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()方法調用。
rú如 guǒ果 nǐ你 xiǎng想 wèi為 zhè這 ge個 xiàng項 mù目 tí提 gōng供 de的 I D zhí值 , shǐ使 yòng用 I I D guān關 jiàn鍵 zì字 cān參 shù數 。 rú如 guǒ果 shěng省 lvè略 cǐ此 cān參 shù數 , jiāng將 shǐ使 yī一 gè個 T T K bìng並 fǎn返 huí回 tā它 de的 jié結 guǒ果 。 i n s e r t ( ) fāng方 fǎ法 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用 cǐ此 fāng方 fǎ法 de的 zhí值 guān關 jiàn鍵 zì字 cān參 shù數 zhǐ指 dìng定 zài在 gāi該 xiàng項 mù目 dì的 měi每 gè個 liè列 zhōng中 yīng應 chū出 xiàn現 de的 shén什 me么 shí時 , tā它 shì是 kě可 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í識 fú符 zì字 fú符 chuàn串 de的 xù序 liè列 。 zhè這 xiē些 zì字 fú符 chuàn串 zài在 nèi內 bù部 shǐ使 yòng用 , yǐ以 què確 dìng定 kòng控 jiàn件 zhōng中 de的 liè列 。 tú圖 biāo標 lán欄 , qí其 biāo標 shí識 fú符 zǒng總 shì是 “ # 0 ” , bāo包 hán含 zhé折 dié疊 / zhǎn展 kāi開 de的 tú圖 biāo標 zǒng總 shì是 dì第 yī一 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了 tú圖 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選 zé擇 shí實 jì際 shang上 xiǎn顯 shì示 de的 liè列 , bìng並 què確 dìng定 tā它 men們 de的 yǎn演 shì示 wén文 gǎo稿 de的 shùn順 xù序 。 jià價 zhí值 guān觀 kě可 néng能 :
• '#all' to select all columns and display them in the order defined by the columns argument.
•”#所有選擇所有列的列參數定義的順序顯示。
• ” # suǒ所 yǒu有 xuǎn選 zé擇 suǒ所 yǒu有 liè列 de的 liè列 cān參 shù數 dìng定 yì義 de的 shùn順 xù序 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 jì計 shù數 ) huò或 liè列 biāo標 shí識 fú符 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()方法需要一個參數值=(名稱、大小、日期)提供的值將被顯示。讓我們將此序列稱為“邏輯列”序列。
lì例 rú如 , jiǎ假 shè設 nǐ你 zhǐ指 dìng定 liè列 = ( ' n a m e ' , ' dà大 xiǎo小 ' , ' rì日 ' ) 。 zhè這 yì意 wèi味 zhe着 měi每 gè個 diàn電 huà話 。 i n s e r t ( ) fāng方 fǎ法 xū需 yào要 yī一 gè個 cān參 shù數 zhí值 = ( míng名 chēng稱 、 dà大 xiǎo小 、 rì日 qī期 ) tí提 gōng供 de的 zhí值 jiāng將 bèi被 xiǎn顯 shì示 。 ràng讓 wǒ我 men們 jiāng將 cǐ此 xù序 liè列 chēng稱 wéi為 “ luó邏 jí輯 liè列 ” xù序 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進 yī一 bù步 jiǎ假 shè設 nǐ你 zhǐ指 dìng定 liè列 = gòu構 zào造 hán函 shù數 ( 2 , 0 ) 。 wù物 lǐ理 liè列 de的 shùn順 xù序 , jiāng將 shí實 jì際 chū出 xiàn現 zài在 xiǎo小 bù部 jiàn件 zhōng中 de的 liè列 , jiāng將 shì是 sān三 : tú圖 biāo標 liè列 jiāng將 shì是 dì第 yī一 gè個 , rán然 hòu后 shì是 shù數 jù據 liè列 ( luó邏 jí輯 liè列 xù序 liè列 zhōng中 de的 suǒ索 yǐn引 2 ) , rán然 hòu后 shì是 “ míng名 chēng稱 ” liè列 ( luó邏 jí輯 liè列 suǒ索 yǐn引 0 ) 。 dà大 xiǎo小 liè列 jiāng將 bù不 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 given |
Left |
Top |
Right |
Bottom |
a |
a |
a |
a |
a |
a b |
a |
b |
a |
b |
a b c |
a |
c |
b |
c |
a b c d |
a |
b |
c |
d |
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è這 lǐ里 yǒu有 yī一 gè個 T r e e V i e w kòng控 jiàn件 de的 shǐ使 yòng用 fāng方 fǎ法 。
.bbox(item, column=None)
.bbox(item
,column=None)
。 B B O X ( xiàng項 mù目 , 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項 mù目 dì的 xiàng項 mù目 , rú如 guǒ果 gāi該 xiàng項 mù目 shì是 mù目 qián前 kě可 jiàn見 de的 , cǐ此 fāng方 fǎ法 fǎn返 huí回 yī一 gè個 yuán元 zǔ組 ( X , Y , W , H ) , qí其 zhōng中 ( x , y ) shì是 gāi該 xiàng項 mù目 dì的 zuǒ左 shàng上 jiǎo角 de的 zuò坐 biāo標 xiāng相 duì對 yú於 kòng控 jiàn件 , hé和 W hé和 H shì是 gāi該 xiàng項 mù目 dì的 kuān寬 dù度 hé和 xiàng像 sù素 gāo高 dù度 。 rú如 guǒ果 gāi該 xiàng項 mù目 shì是 bù不 kě可 jiàn見 de的 , gāi該 fāng方 fǎ法 fǎn返 huí回 yī一 gè個 kōng空 zì字 fú符 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是列的整數索引或它的列標識符。
rú如 guǒ果 shěng省 lvè略 le了 kě可 xuǎn選 de的 liè列 cān參 shù數 , zé則 jiāng將 dé得 dào到 zhěng整 gè個 xíng行 de的 bāo包 wéi圍 hé盒 。 yào要 dé得 dào到 xiàng項 mù目 xíng行 de的 yī一 gè個 tè特 dìng定 liè列 de的 bāo包 wéi圍 kuàng框 , shǐ使 yòng用 liè列 = C , qí其 zhōng中 C shì是 liè列 de的 zhěng整 shù數 suǒ索 yǐn引 huò或 tā它 de的 liè列 biāo標 shí識 fú符 。
.column(cid, option=None, **kw)
.column(cid
, option=None, **kw
)
。 zhù柱 ( C I D , xuǎn選 xiàng項 = wú無 , × × qiān千 wǎ瓦 )
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方 fǎ法 pèi配 zhì置 zhǐ指 dìng定 de的 C I D de的 luó邏 jí輯 liè列 de的 wài外 guān觀 , tā它 kě可 yǐ以 shì是 yī一 gè個 liè列 de的 suǒ索 yǐn引 huò或 liè列 biāo標 shí識 。 pèi配 zhì置 tú圖 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. |
如果提供了沒有選項值或任何其他關鍵字參數,則該方法將返回指定列的列選項的字典。
rú如 guǒ果 tí提 gōng供 le了 méi沒 yǒu有 xuǎn選 xiàng項 zhí值 huò或 rèn任 hé何 qí其 tā他 guān關 jiàn鍵 zì字 cān參 shù數 , zé則 gāi該 fāng方 fǎ法 jiāng將 fǎn返 huí回 zhǐ指 dìng定 liè列 de的 liè列 xuǎn選 xiàng項 de的 zì字 diǎn典 。
• To interrogate the current value of an option named X , use an argument option=X.
•審問的一個選項,命名為x的當前值,使用一個參數選項= x。
• shěn審 wèn問 de的 yī一 gè個 xuǎn選 xiàng項 , mìng命 míng名 wéi為 x de的 dāng當 qián前 zhí值 , shǐ使 yòng用 yī一 gè個 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ǐ匹 pèi配 de的 I I D zhí值 de的 kòng控 jiàn件 de的 suǒ所 yǒu有 wù物 pǐn品 dōu都 shì是 cóng從 kě可 jiàn見 de的 bù部 jiàn件 chāi拆 xià下 , lián連 tóng同 tā他 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當前具有焦點,或“如果沒有項目有焦點。
rú如 guǒ果 nǐ你 bù不 wèi為 zhè這 ge個 fāng方 fǎ法 tí提 gōng供 le了 yī一 zhǒng種 shuō說 fǎ法 , nǐ你 huí回 lái來 huò或 zhě者 wù物 pǐn品 de的 I I D dāng當 qián前 jù具 yǒu有 jiāo焦 diǎn點 , huò或 “ rú如 guǒ果 méi沒 yǒu有 xiàng項 mù目 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í回 yī一 gè個 yuán元 zǔ組 de的 ér兒 tóng童 xiàng項 mù目 de的 xiàng項 mù目 cān參 shù數 zhǐ指 dìng定 de的 I D zhí值 。 rú如 guǒ果 shěng省 lvè略 gāi該 cān參 shù數 , nǐ你 huì會 dé得 dào到 yī一 gè個 yuán元 zǔ組 bāo包 hán含 dǐng頂 jí級 xiàng項 mù目 de的 I I D zhí值 。
.heading(cid, option=None, **kw)
。標題(CID,選項=無,××千瓦)
。 biāo標 tí題 ( C I D , xuǎn選 xiàng項 = wú無 , × × qiān千 wǎ瓦 )
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用 cǐ此 fāng方 fǎ法 kě可 yǐ以 pèi配 zhì置 zài在 zhǐ指 dìng定 de的 C I D zhù柱 bù部 jiàn件 de的 dǐng頂 bù部 xiǎn顯 shì示 de的 liè列 biāo標 tí題 , kě可 yǐ以 shì是 yī一 gè個 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標 tí題 zài在 tú圖 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. |
如果您提供沒有關鍵字參數,該方法將返回一個顯示列標題選項當前設置的字典。
rú如 guǒ果 nín您 tí提 gōng供 méi沒 yǒu有 guān關 jiàn鍵 zì字 cān參 shù數 , gāi該 fāng方 fǎ法 jiāng將 fǎn返 huí回 yī一 gè個 xiǎn顯 shì示 liè列 biāo標 tí題 xuǎn選 xiàng項 dāng當 qián前 shè設 zhì置 de的 zì字 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問 yī一 xiē些 biāo標 tí題 xuǎn選 xiàng項 dāng當 qián前 x de的 zhí值 , shǐ使 yòng用 biǎo表 gé格 xuǎn選 xiàng項 = x cān參 shù數 ; gāi該 fāng方 fǎ法 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定 yī一 gè個 X zuò坐 biāo標 , cǐ此 fāng方 fǎ法 fǎn返 huí回 yī一 gè個 zì字 fú符 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ì示 tú圖 biāo標 liè列 , n de的 zhí值 wèi為 tú圖 biāo標 liè列 de的 0 ; dì第 èr二 gè個 wù物 lǐ理 liè列 de的 2 ; dì第 sān三 gè個 wù物 lǐ理 liè列 de的 1 ; děng等 děng等 。 jì記 de得 , wù物 lǐ理 liè列 shǔ數 kě可 néng能 bù不 tóng同 yú於 luó邏 jí輯 liè列 shǔ數 de的 qíng情 kuàng況 xià下 , nǐ你 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(x
, y
)
返回相對於小部件的位置(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方 fǎ法 lái來 shè設 zhì置 huò或 jiǎn檢 suǒ索 xuǎn選 xiàng項 zhǐ指 dìng定 I I D xiàng項 mù目 nèi內 。 cān參 yuè閱 。 i n s e r t ( ) fāng方 fǎ法 wèi為 xiàng項 mù目 xuǎn選 zé擇 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用 cǐ此 fāng方 fǎ法 jiǎn檢 suǒ索 huò或 shè設 zhì置 liè列 zhí值 de的 xiàng項 zhǐ指 dìng定 I I D 。 yòng用 yī一 gè個 cān參 shù數 , fāng方 fǎ法 fǎn返 huí回 yī一 gè個 zì字 diǎn典 : jiàn鍵 shì是 liè列 biāo標 shí識 fú符 , ér而 měi每 gè個 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用 yī一 gè個 cān參 shù數 shí時 , tā它 fǎn返 huí回 dāng當 qián前 biāo標 jì記 xuǎn選 xiàng項 de的 zì字 diǎn典 。 yào要 fǎn返 huí回 yī一 gè個 tè特 dìng定 xuǎn選 xiàng項 x de的 zhí值 , shǐ使 yòng用 X zuò作 wéi為 dì第 èr二 gè個 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節,“滾動條命令回調”。