treeview(n)
π NAME π
okay bestie, this is the tea on treeview(n) from the BLT Built-In Commands β the manual page for the treeview widget. And what does she do? Create and manipulate hierarchical table widgets. Periodt. π
β¨ SYNOPSIS β¨
treeview pathName ?options?
π¦ DESCRIPTION π¦
The treeview widget displays a tree of data. She literally replaces both the hiertable and hierbox widgets, no cap.
The treeview is 100% syntax compatible with the hiertable widget. The hiertable command is retained for sake of script-level compatibility. This widget obsoletes the hierbox widget. It does everything the old hierbox widget did, but also provides data sharing (via tree data objects) and the ability to tag nodes. iconic behavior, honestly. π
πΈ INTRODUCTION πΈ
The treeview widget displays hierarchical data. Data is represented as nodes in a general-ordered tree. Each node may have sub-nodes, and those sub-nodes can in turn have their own children. it's giving family tree, but make it Unix. π³
A node is displayed as a row entry in the widget. Each entry has a text label and icon. When a node has children, its entry is drawn with a small button to the left of the label. Clicking the mouse over this button opens or closes the node. When a node is open, its children are exposed. When it is closed, the children and their descendants are hidden. The button is normally a + or - symbol (ala Windows Explorer), but can be replaced with a pair of Tk images (open and closed images). cute, customizable, slay. β¨
If the node has data associated with it, that data can be displayed in columns running vertically on either side of the tree. You can control the color, font, etc. of each entry. Any entry label or data field can be edited in-place. lowkey powerful. π«Ά
π TREE DATA OBJECT π
The tree is not stored inside the widget but in a tree data object (see the tree command for a further explanation). Tree data objects can be shared among different clients, such as a treeview widget or the tree command. You can walk the tree and manage its data with the tree command, while displaying it with the treeview widget. Whenever the tree is updated, the treeview widget is automatically redrawn. no manual refresh era. π₯
By default, the treeview widget creates its own tree object. The tree initially contains just a root node. But you can also display trees created by the tree command using the -tree configuration option. Treeview widgets can share the same tree object, possibly displaying different views of the same data. sharing is caring, bestie. π
A tree object has both a Tcl and C API. You can insert or delete nodes using treeview widget or tree command operations, but also from C code. For example, you can load the tree from your C code while still managing and displaying the tree from Tcl. The widget is automatically notified whenever the tree is modified via C or Tcl. main character energy across languages. π
β SYNTAX β
treeview pathName ?option value?...
The treeview command creates a new window pathName and makes it into a treeview widget. At the time this command is invoked, there must not exist a window named pathName, but pathName's parent must exist. Additional options may be specified on the command line or in the option database to configure aspects of the widget such as its colors and font. See the configure operation below for the exact details about what option and value pairs are valid.
If successful, treeview returns the path name of the widget. It also creates a new Tcl command by the same name. You can use this command to invoke various operations that query or modify the widget. The general form is:
pathName operation ?arg?...
Both operation and its arguments determine the exact behavior of the command. The operations available are described in the TREEVIEW OPERATIONS section. iykyk. π
π§ IDS AND TAGS π§
Nodes can be inserted into a tree using the treeview widget, like this:
blt::treeview .t
set node [.t insert end root "one"]
or with the tree command, like this:
set tree [blt::tree create]
set node [$tree insert root "one"]
In both cases, a number identifying the node is returned (the value of $node). This serial number or id uniquely identifies the node. Please note that you can't infer a location or position of a node from its id. The only exception is that the root node is always id 0. Since nodes may have the same labels or be moved within the tree, ids provide a convenient way to identify nodes. If a tree is shared, the ids will be the same regardless if you are using by the treeview widget or the tree command. Ids are recycled when the node deleted. okay recycle queen β»οΈ
A node may also have any number of tags associated with it. A tag is just a string of characters, and it may take any form except that of an integer. For example, "x123" is valid, but "123" isn't. The same tag may be associated with many different nodes. This is typically done to associate a group of nodes. Many operations in the treeview widget take either node ids or tag names as arguments. Using a tag says to apply the operation to all nodes with that tag.
The tag all is implicitly associated with every node in the tree. It may be used to invoke operations on all the nodes in the tree.
Tags may be shared, just like trees, between clients. For example, you can use the tags created by the tree command with treeview widgets. sharing tags too? we love a collaborative ecosystem. π
π SPECIAL NODE IDS π
There are also several special non-numeric ids. Special ids differ from tags in that they are always translated to their numeric equivalent. They also take precedence over tags. For example, you can't use a tag name that is a special id. These ids are specific to the treeview widget.
activeβ The node where the mouse pointer is currently located. When a node is active, it is drawn using its active icon (see the-activeiconoption). The active id is changed automatically by moving the mouse pointer over another node or by using theentry activateoperation. Note that there can be only one active node at a time.anchorβ The node representing the fixed end of the current selection. The anchor is set by theselection anchoroperation.currentβ The node where the mouse pointer is currently located. But unlikeactive, this id changes while the selection is dragged. It is used to determine the current node during button drags.downβ The next open node from the current focus. Thedownof the last open node is the same.endβ The last open node (in depth-first order) on the tree.focusβ The node that currently has focus. When a node has focus, it receives key events. To indicate focus, the node is drawn with a dotted line around its label. You can change the focus using thefocusoperation.lastβ The last open node from the current focus. But unlikeup, when the focus is at root,lastwraps around to the last open node in the tree.markβ The node representing the non-fixed end of the current selection. The mark is set by theselection markoperation.nextβ The next open node from the current focus. But unlikedown, when the focus is on last open node,nextwraps around to the root node.nextsiblingβ The next sibling from the node with the current focus. If the node is already the last sibling then it is thenextsibling.parentβ The parent of the node with the current focus. The parent of the root is also the root.prevsiblingβ The previous sibling from the node with the current focus. If the node is already the first sibling then it is theprevsibling.rootβ The root node. You can also use id0to indicate the root.upβ The last open node (in depth-first order) from the current focus. Theupof the root node (i.e. the root has focus) is also the root.view.topβ First node that's current visible in the widget.view.bottomβ Last node that's current visible in the widget.pathβ Absolute path of a node. Path names refer to the node name, not their entry labels. Paths don't have to start with a separator (see the-separatorconfiguration option), but component names must be separated by the designated separator.@x,yβ Indicates the node that covers the point in thetreeviewwindow specified byxandy(in pixel coordinates). If no part of the entryd covers that point, then the closest node to that point is used.
A node may be specified as an id or tag. If the specifier is an integer then it is assumed to refer to the single node with that id. If the specifier is not an integer, it's checked to see if it's a special id (such as focus). Otherwise, it's assumed to be tag.
Some operations only operate on a single node at a time; if a tag refers to more than one node, then an error is generated. bestie, read the room: single node only. π
π DATA FIELDS π
A node in the tree can have data fields. A data field is a name-value pair, used to represent arbitrary data in the node. Nodes can contain different fields (they aren't required to contain the same fields). You can optionally display these fields in the treeview widget in columns running on either side of the displayed tree. A node's value for the field is drawn in the column along side its node in the hierarchy. Any node that doesn't have a specific field is left blank. Columns can be interactively resized, hidden, or, moved. flexible layout? we love to see it. π
π¦ ENTRY BINDINGS π¦
You can bind Tcl commands to be invoked when events occur on nodes (much like Tk canvas items). You can bind a node using its id or its bindtags. Bindtags are simply names that associate a binding with one or more nodes. There is a built-in tag all that all node entries automatically have. built-in all tag? she's always invited. π
π TREEVIEW OPERATIONS π
The treeview operations get invoked by specifying the widget's pathname, the operation, and any arguments that pertain to that operation. The general form is:
pathName operation ?arg arg ...?
Operation and the args determine the exact behavior of the command. The following operations are available for treeview widgets:
pathName bbox ?-screen? tagOrId... β okay so this one is literally the bounding-box bestie π
. It returns a list of 4 numbers, representing a bounding box around the specified entries. You give it one or more tagOrId arguments. If the -screen flag is present, then the x-y coordinates of the bounding box come back as screen coordinates, not virtual coordinates. Virtual coordinates start from 0 from the root node. The returned list contains these values:
xβ X-coordinate of the upper-left corner of the bounding box.yβ Y-coordinate of the upper-left corner of the bounding box.widthβ Width of the bounding box.heightβ Height of the bounding box.
pathName bind tagName ?sequence command? β associates command with tagName so that whenever the event sequence given by sequence occurs for a node with this tag, command gets invoked. The syntax is similar to the bind command except that it operates on treeview entries, rather than widgets. See the bind manual entry for complete details on sequence and the substitutions performed on command before invoking it.
If all arguments are specified then a new binding is created, replacing any existing binding for the same sequence and tagName. If the first character of command is + then command augments an existing binding rather than replacing it. If no command argument is provided then the command currently associated with tagName and sequence is returned β itβs an error if thereβs no such binding. If both command and sequence are missing then you get a list of all the event sequences for which bindings have been defined for tagName.
pathName button operation ?args? β this command is used to control the button selectors within a treeview widget. It has several forms, depending on operation:
pathName button activate tagOrIdβ designates the node given bytagOrIdas active. When a node is active its entry is drawn using its active icon (see the-activeiconoption). Note that there can be only one active entry at a time. The special idactiveindicates the currently active node.pathName button bind tagName ?sequence command?β associatescommandwithtagNameso that whenever the event sequence given bysequenceoccurs for a button of a node entry with this tag,commandgets invoked. The syntax is similar to thebindcommand except that it operates on treeview buttons, rather than widgets. See thebindmanual entry for complete details onsequenceand the substitutions performed oncommandbefore invoking it.
If all arguments are specified then a new binding is created, replacing any existing binding for the same sequence and tagName. If the first character of command is + then command augments an existing binding rather than replacing it. If no command argument is provided then the command currently associated with tagName and sequence is returned β itβs an error if thereβs no such binding. If both command and sequence are missing then you get a list of all the event sequences for which bindings have been defined for tagName.
pathName button cget optionβ returns the current value of the configuration option given byoption.optionmay have any of the values accepted by theconfigureoperation described below.pathName button configure ?option? ?value option value ...?β query or modify the configuration options of the widget. If nooptionis specified, returns a list describing all of the available options forpathName(seeTk_ConfigureInfofor information on the format of this list). Ifoptionis specified with novalue, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if nooptionis specified). If one or moreoption-valuepairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string.Optionandvalueare described in the section BUTTON OPTIONS below.
pathName cget option β returns the current value of the configuration option given by option. option may have any of the values accepted by the configure operation described below.
pathName close ?-recurse? tagOrId... β closes the node specified by tagOrId. In addition, if a Tcl script was specified by the -closecommand option, it is invoked. If the node is already closed, this command has no effect. If the -recurse flag is present, each child node is recursively closed.
pathName column operation ?args? β the following operations are available for treeview columns.
pathName column activate columnβ sets the active column tocolumn.Columnis the name of a column in the widget. When a column is active, itβs drawn using its-activetitlebackgroundand-activetitleforegroundoptions. Ifcolumnis the"", then no column will be active. If nocolumnargument is provided, then the name of the currently active column is returned.pathName column cget name optionβ returns the current value of the column configuration option given byoptionforname.Nameis the name of column that corresponds to a data field.Optionmay have any of the values accepted by theconfigureoperation described below.pathName column configure name ?option? ?value option value ...?β query or modify the configuration options of the column designated byname.Nameis the name of the column corresponding to a data field. If nooptionis specified, returns a list describing all of the available options forpathName(seeTk_ConfigureInfofor information on the format of this list). Ifoptionis specified with novalue, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if nooptionis specified). If one or moreoption-valuepairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string.Optionandvalueare described in the section COLUMN OPTIONS below.pathName column delete field ?field...?β deletes one or more columns designated byfield. Note that this does not delete the data fields themselves.pathName column insert position field ?options...?β inserts one or more columns designated byfield. A column displays each nodeβs data field by the same name. If the node doesnβt have the given field, the cell is left blank.Positionindicates where in the list of columns to add the new column. It may be either a number orend.pathName column invoke fieldβ invokes the Tcl command associated with the columnfield, if there is one (using the columnβs-commandoption). The command is ignored if the columnβs-stateoption set todisabled.pathName column move name destβ moves the columnnameto the destination position.Destis the name of another column or a screen position in the form@x,y.pathName column namesβ returns a list of the names of all columns in the widget. The list is ordered as the columns are drawn from left-to-right.pathName column nearest x ?y?β returns the name of the column closest to the given X-Y screen coordinate. If you provide ayargument (itβs optional), a name is returned only when if the point is over a columnβs title.
pathName configure ?option? ?value option value ...? β query or modify the configuration options of the widget. If no option is specified, returns a list describing all of the available options for pathName (see Tk_ConfigureInfo for information on the format of this list). If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more option-value pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. Option and value are described in the section TREEVIEW OPTIONS below.
pathName curselection β returns a list containing the ids of all of the entries that are currently selected. If there are no entries selected, then the empty string is returned.
pathName delete tagOrId... β deletes one or more entries given by tagOrId and its children.
pathName entry operation ?args? β the following operations are available for treeview entries.
pathName entry activate tagOrIdβ sets the active entry to the one specified bytagOrId. When an entry is active it is drawn using its active icon (see the-activeiconoption). Note that there can be only one active node at a time. The special id of the currently active node isactive.pathName entry cget optionβ returns the current value of the configuration option given byoption.Optionmay have any of the values accepted by theconfigureoperation described below.
pathName entry children tagOrId ?first? ?last?
Okay so this one spills the ids of the children under tagOrId π
where tagOrId is the id or tag of the node you're examining, obvi. If you only pass a first argument, you get back the id of the child sitting at that numeric position. If you give both first and last, you get ids of all the children in that range. And if you give neither? You get ids of all the children. Iconic, no notes.
pathName entry configure ?option? ?value option value ...?
Your classic query-or-modify situation β¨ β it messes with the configuration options of the widget.
- No
optionat all β returns a list describing all the available options forpathName(peepTk_ConfigureInfofor the format of that list π). optiongiven but novalueβ returns a list describing that one named option, and that list is literally identical to the corresponding sublist of the value you'd get if no option was specified.- One or more option-value pairs β the command modifies the given widget option(s) to the given value(s), and in this case it returns an empty string.
option and value are described below:
pathName entry delete tagOrId ?first ?last?
Deletes one or more children nodes of the parent tagOrId π«Ά. If first and last are there, they're positions designating a range of children nodes to be deleted. Poof, gone.
pathName entry isbefore tagOrId1 tagOrId2
Returns 1 if tagOrId1 is before tagOrId2, and 0 otherwise. Simple king behavior π.
pathName entry ishidden tagOrId
Returns 1 if the node is currently hidden and 0 otherwise. Heads up though: a node also counts as hidden if any of its ancestor nodes are closed or hidden π β the vibe is inherited, fr fr.
pathName entry isopen tagOrId
Returns 1 if the node is currently open and 0 otherwise. That's it, that's the whole thing πΈ.
pathName entry size -recurse tagOrId
Returns the number of children for parent node tagOrId. If the -recurse flag is set, you get the number of all its descendants instead. The node itself is not counted β it's not about them π.
pathName find ?flags? first last
Finds all the entries matching the criteria given by flags, and returns a list of ids for all matching nodes π₯. first and last are ids designating the range of the search in depth-first order. And plot twist: if last is before first, then the nodes get searched in reverse order π. The valid flags are:
-name patternβ pattern to match against node names.-full patternβ pattern to match against node pathnames.-option patternβ pattern to match against the node entry's configuration option.-exactβ patterns must match exactly. This is the default.-globβ use global pattern matching, C-shell style π. For two strings to match, their contents must be identical except that these special sequences may appear in pattern:*β matches any sequence of characters in string, including a null string.?β matches any single character in string.[chars]β matches any character in the set given by chars. If a sequence of the formx-yappears in chars, then any character betweenxandy, inclusive, will match.\xβ matches the single characterx. This is the escape hatch for when you need to dodge the special interpretation of the characters*?[]\in the pattern π.
-regexpβ use regular expression pattern matching (i.e. the same as implemented by theregexpcommand).-nonmatchingβ pick entries that don't match. Petty and valid π .-exec stringβ a Tcl script to be invoked for each matching node. Percent substitutions get performed on string before it's executed. The valid substitutions are:%Wβ the pathname of the widget.%pβ the name of the node.%Pβ the full pathname of the node.%#β the id of the node.%%β translates to a single percent.
-count numberβ stop searching after number matches.--β indicates the end of flags.
pathName focus tagOrId
Sets the focus to the node given by tagOrId β. When a node has focus it can receive keyboard events β main character energy only. And the special id focus designates the node that currently has focus, iykyk.
pathName get ?-full? tagOrId tagOrId...
Translates one or more ids into their node entry names π¦ and returns a list of names for all the ids you specified. If the -full flag is set, then the full pathnames come back instead.
pathName hide ?flags? tagOrId...
Hides all nodes matching the criteria given by flags, and the search is performed recursively for each node given by tagOrId π. The valid flags are:
-name patternβ pattern to match against node names.-full patternβ pattern to match against node pathnames.-option patternβ pattern to match against the node entry's configuration option.-exactβ match patterns exactly. This is the default.-globβ use global pattern matching, C-shell style π. Same deal: contents must be identical except for these special sequences in pattern:*β matches any sequence of characters in string, including a null string.?β matches any single character in string.[chars]β matches any character in the set given by chars. If a sequence of the formx-yappears in chars, then any character betweenxandy, inclusive, will match.\xβ matches the single characterx. This provides a way of avoiding the special interpretation of the characters*?[]\in the pattern π.
-regexpβ use regular expression pattern matching (i.e. the same as implemented by theregexpcommand).-nonmatchingβ hide nodes that don't match. Chaotic, love it π.--β indicates the end of flags.
pathName index ?-at tagOrId? string
Returns the id of the node specified by string, which may be a tag or a node id β¨. Some special ids are normally relative to the node that has focus β and the -at flag lets you select another node instead. Flexible queen behavior π.
pathName insert ?-at tagOrId? position path ?options...? ?path? ?options...?
Inserts one or more nodes at position π±. position is the location (a number, or end) where the new nodes get added to the parent node. path is the pathname of the new node.
Pathnames can be formatted either as a Tcl list (each element is a path component) or as a string separated by a special character sequence, using the -separator option. Pathnames are normally absolute, but the -at switch lets you select a relative starting point β its value is the id of the starting node.
real talk bestie: all ancestors of the new node must already exist, unless the-autocreateoption is set. It is also an error if a node already exists, unless the-allowduplicatesoption is set. respect the rules or catch the error π
option and value may have any of the values accepted by the entry configure operation described in the ENTRY OPERATIONS section below. This command returns a list of the ids of the new entries π.
pathName move tagOrId how destId
Moves the node given by tagOrId to the destination node π. Two rules, no exceptions: the node can not be an ancestor of the destination, and destId β which is the id of the destination node β can not be the root of the tree. In conjunction with how, it describes how the move is performed:
beforeβ moves the node before the destination node.afterβ moves the node after the destination node.intoβ moves the node to the end of the destination's list of children.
pathName nearest x y ?varName?
Returns the id of the node entry closest to the given X-Y screen coordinate π―. The optional varName is the name of a variable which gets set to either button or select to indicate over what part of the node the coordinate lies. And if the coordinate isn't directly over any node, varName will contain the empty string π.
pathName open ?-recurse? tagOrId...
Opens the one or more nodes specified by tagOrId πΈ. If a node isn't already open, the Tcl script specified by the -opencommand option is invoked. If the -recurse flag is present, then each descendant gets recursively opened too β open everything, honestly π
.
pathName range ?-open? first last
Returns the ids, in depth-first order, of the nodes between the first and last ids π¦. If the -open flag is present, it says to consider only open nodes. And if last is before first, the ids come back in reverse order. We contain multitudes π.
pathName scan option args
This command implements scanning, and it has two forms depending on option:
pathName scan mark x y
Records x and y and the current view in the treeview window β used in conjunction with later scan dragto commands π«Ά. Typically this command is associated with a mouse button press in the widget. It returns an empty string.
pathName scan dragto x y
Okay so this one's a little math gremlin β¨ It computes the difference between its x and y arguments and the x and y arguments from the last scan mark command for the widget. Then it adjusts the view by 10 times the difference in coordinates. Basically it's the "drag the list at high speed through the window" effect β this command is typically associated with mouse motion events in the widget, to produce the effect of dragging the list at high speed through the window. The return value is an empty string. π«Ά
pathName see ?-anchor anchor? tagOrId
Adjusts the view of entries so that the node given by tagOrId is visible in the widget window π Heads up: it's an error if tagOrId is a tag that refers to more than one node. By default the node's entry is displayed in the middle of the window. That can changed using the -anchor flag β its value is a Tk anchor position.
pathName selection option arg
This command is used to adjust the selection within a treeview widget, and it has several forms depending on option π
pathName selection anchor tagOrIdβ Sets the selection anchor to the node given by tagOrId. If tagOrId refers to a non-existent node, then the closest node is used. The selection anchor is the end of the selection that is fixed while dragging out a selection with the mouse. The special idanchormay be used to refer to the anchor node.pathName selection cancelβ Clears the temporary selection of entries back to the current anchor. Temporary selections are created by theselection markoperation.pathName selection clear first ?last?β Removes the entries between first and last (inclusive) from the selection. Both first and last are ids representing a range of entries. If last isn't given, then only first is deselected. Entries outside the selection are not affected.pathName selection clearallβ Clears the entire selection. Bye bye selection πpathName selection mark tagOrIdβ Sets the selection mark to the node given by tagOrId. This causes the range of entries between the anchor and the mark to be temporarily added to the selection. The selection mark is the end of the selection that is fixed while dragging out a selection with the mouse. The special idmarkmay be used to refer to the current mark node. If tagOrId refers to a non-existent node, then the mark is ignored. Resetting the mark will unselect the previous range. Setting the anchor finalizes the range.pathName selection includes tagOrIdβ Returns1if the node given by tagOrId is currently selected,0if it isn't.pathName selection presentβ Returns1if any nodes are currently selected and0otherwise.pathName selection set first ?last?β Selects all of the nodes in the range between first and last, inclusive, without affecting the selection state of nodes outside that range.pathName selection toggle first ?last?β Selects/deselects nodes in the range between first and last, inclusive, from the selection. If a node is currently selected, it becomes deselected, and visa versa.
pathName show ?flags? tagOrId...
Exposes all nodes matching the criteria given by flags. This is the inverse of the hide operation β¨ The search is performed recursively for each node given by tagOrId. The valid flags are described below:
-name patternβ Specifies pattern to match against node names.-full patternβ Specifies pattern to match against node pathnames.-option patternβ Specifies pattern to match against the entry's configuration option.-exactβ Match patterns exactly. The is the default.-globβ-globUse global pattern matching. Matching is done in a fashion similar to that used by the C-shell. For the two strings to match, their contents must be identical except that the following special sequences may appear in pattern:*β Matches any sequence of characters in string, including a null string.?β Matches any single character in string.[chars]β Matches any character in the set given by chars. If a sequence of the formx-yappears in chars, then any character betweenxandy, inclusive, will match.\xβ Matches the single characterx. This provides a way of avoiding the special interpretation of the characters*?[]\in the pattern.
-regexpβ Use regular expression pattern matching (i.e. the same as implemented by theregexpcommand).-nonmatchingβ Expose nodes that don't match.--β Indicates the end of flags.
pathName sort ?operation? args...
pathName sort auto ?boolean
Turns on/off automatic sorting of node entries π If boolean is true, entries will be automatically sorted as they are opened, closed, inserted, or deleted. If no boolean argument is provided, the current state is returned.
pathName sort cget option
Returns the current value of the configuration option given by option. Option may have any of the values accepted by the configure operation described below.
pathName sort configure ?option? ?value option value ...?
Query or modify the sorting configuration options of the widget. If no option is specified, returns a list describing all of the available options for pathName (see Tk_ConfigureInfo for information on the format of this list). If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more option-value pairs are specified, then the command modifies the given sorting option(s) to have the given value(s); in this case the command returns an empty string. Option and value are described below:
-column stringβ Specifies the column to sort. Entries in the widget are rearranged according to this column. If column is""then no sort is performed.-command stringβ Specifies a Tcl procedure to be called when sorting nodes. The procedure is called with three arguments: the pathname of the widget and the fields of two entries. The procedure returns1if the first node is greater than the second,-1is the second is greater, and0if equal.-decreasing booleanβ Indicates to sort in ascending/descending order. If boolean is true, then the entries as in descending order. The default isno.-mode stringβ Specifies how to compare entries when sorting. String may be one of the following:asciiβ Use string comparison based upon the ASCII collation order.dictionaryβ Use dictionary-style comparison. This is the same asasciiexcept (a) case is ignored except as a tie-breaker and (b) if two strings contain embedded numbers, the numbers compare as integers, not characters. For example,"bigBoy"sorts between"bigbang"and"bigboy", and"x10y"sorts between"x9y"and"x11y".integerβ Compares fields as integers.realβ Compares fields as floating point numbers.commandβ Use the Tcl proc specified by the-commandoption to compare entries when sorting. If no command is specified, the sort reverts toasciisorting.
pathName sort once ?flags? tagOrId...
Sorts the children for each entries specified by tagOrId πΈ By default, entries are sorted by name, but you can specify a Tcl proc to do your own comparisons.
-recurseβ Recursively sort the entire branch, not just the children.
pathName tag operation args
Tags are a general means of selecting and marking nodes in the tree, and honestly? iconic π A tag is just a string of characters, and it may take any form except that of an integer. The same tag may be associated with many different nodes.
Both operation and its arguments determine the exact behavior of the command. The operations available for tags are listed below.
pathName tag add string id...β Adds the tag string to one of more entries.pathName tag delete string id...β Deletes the tag string from one or more entries.pathName tag forget stringβ Removes the tag string from all entries. It's not an error if no entries are tagged as string.pathName tag names ?id?β Returns a list of tags used. If an id argument is present, only those tags used by the node designated by id are returned.pathName tag nodes stringβ gimme a list of every id that's rockin' the tag string. Nobody tagged with it? You get an empty string back. That's it, that's the whole thing. πpathName text operation ?args?β this is the one that handles text editing for cells (aka data fields inside a column) or for entry labels. It's got a bunch of different forms depending on what operation you pass, so buckle up bestie:pathName text applyβ commits the edited buffer, so it replaces the entry label or the data field. Edit window gets hidden. Slay, changes saved. πpathName text cancelβ nope, never mind, undo my whole life. Reverts the entry label or data value back to whatever it was before, and hides the edit window. πpathName text cget valueβ hands you back the current value of the configuration option given by option. Option can be literally any of the values that theconfigureoperation (below) accepts. iykyk.pathName text configure ?option value?β query or modify the configuration options of the edit window. No option given? It returns a list describing all the available options (peepTk_ConfigureInfofor what that list's format looks like). Give just option with no value? Then you get a list describing that one named option β and that list is identical to the matching sublist of the no-option version. And if you pass one or more option-value pairs, the command modifies the given widget option(s) to have the given value(s) β in which case you get an empty string back. Option and value are described down in TEXT EDITING OPTIONS. β¨pathName text delete first lastβ yeets the characters in the edit buffer that sit between the two character positions you gave it.pathName text get ?-root? x yβ fr the original page does not describe this one, it just lists it. Not me inventing behaviour, so I'm leaving it exactly as-is, no cap. πpathName text icursor indexβ same deal, listed with zero explanation. Present, accounted for, unbothered. πpathName text index indexβ returns the text index of the given index.pathName text insert index stringβ drops the text string into the edit buffer at index. Like,0will prepend the buffer. Firsties! πΈpathName text selection argsβ controls the selection of the editing window. Heads up bestie: this is not the same as the selection of entries. It comes in these forms:pathName text selection adjust indexβ adjusts either the first or the last index of the selection.pathName text selection clearβ clears the selection. gone. poof. β¨pathName text selection from indexβ sets the anchor of the selection.pathName text selection presentβ tells you whether a selection is present at all.pathName text selection range start endβ sets both the anchor and the mark of the selection, in one go.pathName text selection to indexβ sets the unanchored end (the mark) of the selection.
pathName toggle tagOrIdβ opens or closes the node given by tagOrId. And if the matching-opencommandor-closecommandoption is set, that command also gets invoked. Double trouble, but make it cute. π¦pathName xview argsβ query and change the horizontal position of the stuff in the widget's window. Takes any of these forms:pathName xviewβ returns a list of two elements, each a real fraction between0and1, and together they describe the horizontal span that's visible in the window. Example, because examples ate: if the first element is.2and the second is.6, then 20% of the treeview widget's text is off-screen to the left, the middle 40% is visible in the window, and 40% is off-screen to the right. These are the exact same values passed to scrollbars via the-xscrollcommandoption. π«ΆpathName xview tagOrIdβ adjusts the view so the character position given by tagOrId is displayed at the left edge of the window. Character positions are defined by the width of the character0.pathName xview moveto fractionβ adjusts the view so that fraction of the total width of the treeview widget's text is off-screen to the left. fraction must be a fraction between0and1.pathName xview scroll number whatβ shifts the view left or right based on number and what. Number has to be an integer. What must be eitherunitsorpages(or an abbreviation of one of those). If what isunits, the view adjusts left or right by number character units (remember, the width of the0character) on the display; if it'spages, the view adjusts by number screenfuls. Negative number? Characters farther to the left become visible. Positive number? Characters farther to the right become visible. β
pathName yview ?args?β query and change the vertical position of the text in the widget's window. Forms, in order:pathName yviewβ returns a list of two elements, both real fractions between0and1. The first element gives the position of the node at the top of the window, relative to the widget as a whole (0.5means it's halfway through the treeview window, for instance). The second element gives the position of the node just after the last one in the window, again relative to the widget as a whole. These are the same values passed to scrollbars via the-yscrollcommandoption. π§pathName yview tagOrIdβ adjusts the view so the node given by tagOrId is displayed at the top of the window.pathName yview moveto fractionβ adjusts the view so the node given by fraction appears at the top of the window. Fraction is a fraction between0and1;0indicates the first node,0.33indicates the node one-third of the way through the treeview widget, and so on. math girlie behaviour fr fr πpathName yview scroll number whatβ adjusts the view up or down based on number and what. Number must be an integer. What must be eitherunitsorpages. If what isunits, the view adjusts up or down by number lines; if it'spages, the view adjusts by number screenfuls. Negative number? Earlier nodes become visible. Positive number? Later nodes become visible. π₯
In addition to the configure operation, widget configuration options can also be set with the Tk option command. The class resource name is TreeView. β¨
option add *TreeView.Foreground white
option add *TreeView.Background blue
Here's the full lineup of widget options, bestie β every single one, no skips:
-activebackgroundcolor β sets the background color for active entries. A node counts as active when the mouse passes over its entry, or when you use theactivateoperation. π±οΈ-activeforegroundcolor β sets the foreground color of the active node. (Same deal: a node is active when the mouse hovers over its entry or via theactivateoperation.)-activeiconsimages β the images shown for an entry's icon while it's active. images is a list of two Tk images: first one shows when the node is open, second when it's closed. π-autocreateboolean β if boolean is true, missing ancestor nodes get created automatically when you insert new nodes. Otherwise it flags an error. Default isno.-allowduplicatesboolean β if boolean is true, nodes with duplicate pathnames are allowed when inserting new nodes. Otherwise it flags an error. Default isno. π-backgroundcolor β sets the background color of the widget. Default iswhite.-borderwidthpixels β sets the width of the 3-D border around the outside edge of the widget. The-reliefoption decides whether that border actually gets drawn. Default is2.-closecommandstring β a Tcl script to invoke when a node is closed. You can override this per-entry with the entry's-closecommandoption. Default is"". Percent substitutions happen on string before it runs, and these are the valid ones:%Wβ the pathname of the widget.%pβ the name of the node.%Pβ the full pathname of the node.%#β the id of the node.%%β translates to a single percent.
-cursorcursor β specifies the widget's cursor. Default cursor is"".-dashesnumber β sets the dash style of the horizontal and vertical lines drawn connecting entries. number is the length in pixels of the dashes and gaps in the line. If number is0, solid lines get drawn. Default is1(dotted). β¨-exportselectionboolean β says whether the selection is exported. If the widget exports its selection, it observes the standard X11 protocols for handling the selection. Selections are available as typeSTRING; the value of the selection is the label of the selected nodes, separated by newlines. Default isno.-flatboolean β whether to display the tree as a flattened list. If boolean is true, the hierarchy becomes a list of full paths for the nodes. This option also affects sorting β peep theSORT OPERATIONSsection for the deets. Default isno.-focusdashesdashList β sets the dash style of the outline rectangle drawn around the entry label of the node that currently has focus. Number is the length in pixels of the dashes and gaps in the line. If number is0, a solid line gets drawn. Default is1.-focusforegroundcolor β sets the color of the focus rectangle. Default isblack.-fontfontName β the font for entry labels. You can override this per-entry with the entry's-fontconfiguration option. Default is*-Helvetica-Bold-R-Normal-*-12-120-*.-foregroundcolor β the text color of entry labels. Override per-entry with the entry's-foregroundconfiguration option. Default isblack.-heightpixels β the requested height of the widget. Default is400.-hiderootboolean β if boolean is true, no entry for the root node gets displayed. Default isno.-highlightbackgroundcolor β the normal color of the traversal highlight region when the widget doesn't have the input focus.-highlightcolorcolor β the color of the traversal highlight rectangle when the widget does have the input focus. Default isblack.-highlightthicknesspixels β the width of the highlight rectangle that shows when the widget has input focus. The value can take any of the forms acceptable toTk_GetPixels. If the value is zero, no focus highlight is displayed. Default is2.-iconsimages β the images for the entry's icon. images is a list of two Tk images: first shows when the node is open, second when it's closed. π¦-linecolorcolor β the color of the connecting lines drawn between entries. Default isblack.-linespacingpixels β the number of pixels of spacing between entries. Default is0.-linewidthpixels β the width of the lines drawn connecting entries. If pixels is0, no vertical or horizontal lines get drawn at all. Default is1.-opencommandstring β a Tcl script to invoke when a node is opened. Override per-entry with the entry's-opencommandconfiguration option. Default is"". Percent substitutions happen on string before it runs, and these are the valid ones:%Wβ the pathname of the widget.%pβ the name of the node.%Pβ the full pathname of the node.%#β the id of the node.%%β translates to a single percent.
-reliefrelief β the 3-D effect for the widget. relief says how the treeview widget should appear relative to the widget it's packed into; like,raisedmeans the treeview widget should look like it's protruding. Default issunken.-scrollmodemode β the style of scrolling to use. Valid styles are below. The default ishierbox.listboxβ like the listbox widget, the last entry can always be scrolled to the top of the widget window. This lets the scrollbar thumb shrink as the last entry scrolls upward.hierboxβ like the hierbox widget, the last entry can only be viewed at the bottom of the widget window. The scrollbar stays a constant size.canvasβ like the canvas widget, the entries are bound within the scrolling area.
-selectbackgroundcolor β the background color of selected node entries. Default is#ffffea.-selectborderwidthpixels β the width of the raised 3-D border drawn around the labels of selected entries. Default is0.-selectcommandstring β a Tcl script to invoke when the set of selected nodes changes. Default is"".-selectforegroundcolor β the color of the labels of selected node entries. Default isblack.-selectmodemode β the selection mode. If mode issingle, only one node can be selected at a time. Ifmultiple, more than one node can be selected. Default issingle. π-separatorstring β the character sequence used when splitting path components. The separator can be several characters wide (like"::"). Consecutive separators in a pathname are treated as one. If string is the empty string, the pathnames are Tcl lists, and each element is a path component. Default is"".-showtitlesboolean β if boolean is false, column titles don't get displayed. Default isyes.-sortselectionboolean β if boolean is true, nodes in the selection are ordered as they're currently displayed (depth-first or sorted), not in the order they were selected. Default isno.-takefocusfocus β info used when moving focus from window to window via keyboard traversal (like Tab and Shift-Tab). If focus is0, this window gets skipped entirely during keyboard traversal.1means this window should always receive the input focus. An empty value means the traversal scripts decide whether to focus on the window. Default is"1".-trimstring β a string of leading characters to trim from entry pathnames before parsing. This only makes sense if-separatoris also set. Default is"".-widthpixels β the requested width of the widget. If pixels is0, the width is computed from the contents of the treeview widget. Default is200.-xscrollcommandstring β the prefix for a command used to talk to horizontal scrollbars. Whenever the horizontal view in the widget's window changes, the widget generates a Tcl command by concatenating the scroll command and two numbers. If this option isn't specified, no command gets executed.-xscrollincrementpixels β the horizontal scrolling distance. Default is20pixels.-yscrollcommandstring β the prefix for a command used to talk to vertical scrollbars. Whenever the vertical view in the widget's window changes, the widget generates a Tcl command by concatenating the scroll command and two numbers. If this option isn't specified, no command gets executed.-yscrollincrementpixels β the vertical scrolling distance. Default is20pixels.
β¨ ENTRY OPTIONS β¨
okay so bestie, here's the tea: a TON of widget configuration options have glow-up twins living down at the entry level π
Like, -closecommand is a config option for both the whole widget and for individual entries. Options you set at the widget level are global β they apply to every single entry. But if you set that same option on an entry, the entry's version wins and overrides the widget one. Why? To avoid wasting memory by replicating options everywhere, which is honestly so real of them. Most entries are gonna have redundant options, no cap.
Also important: there's no resource class or name for entries. Periodt.
-activeiconsimages β tells the entry which images to show as its icon when it's active. This overrides the global-activeiconsconfig option for this specific entry. Images is a list of two Tk images: the first one shows when the node is open, the second when it's closed. π¦-bindtagstagList β sets the binding tags for nodes. tagList is a list of binding tag names, and the tags plus their order decide how events get handled for nodes. Every tag in the list that matches the current event sequence gets its Tcl command executed. Default value isall.-buttonstring β says whether a button should show up on the left side of the node entry. string can beyes,no, orauto. If it'sauto, then a button is automatically displayed if the node has children. That's the default, bestie. π-closecommandstring β a Tcl script to invoke when the node is closed. This overrides the global-closecommandoption for this entry. Default is"". Percent substitutions get performed on string before it runs, and the valid ones are:%Wβ the pathname of the widget.%pβ the name of the node.%Pβ the full pathname of the node.%#β the id of the node.%%β translates to a single percent.
-datastring β sets data fields for the node. string is a list of name-value pairs to be set. Default is"".-fontfontName β sets the font for entry labels. This overrides the widget's-fontoption for this node. Default is*-Helvetica-Bold-R-Normal-*-12-120-*. π-foregroundcolor β sets the text color of the entry label. This overrides the widget's-foregroundconfiguration option. Default is"".-iconsimages β the images to display for the entry's icon. This overrides the global-iconsconfiguration option. images is a list of two Tk images: first one shows when the node is open, second when it's closed. πΈ-labelstring β sets the text for the entry's label. If you don't set it, it defaults to the name of the node. The default is"".-opencommandstring β a Tcl script to invoke when the entry is opened. This overrides the widget's-opencommandoption for this node. Default is"". Percent substitutions get performed on string before it runs, and the valid ones are:%Wβ the pathname of the widget.%pβ the name of the node.%Pβ the full pathname of the node.%#β the id of the node.%%β translates to a single percent.
π BUTTON OPTIONS π
Button config options can also be set with the option command, iykyk. The resource subclass is Button. The resource name is always button.
option add *TreeView.Button.Foreground white
option add *TreeView.button.Background blue
Here are all the config options you can use on buttons, bestie:
-activebackgroundcolor β sets the background color of active buttons. A button becomes active when the mouse passes over it or via thebutton activateoperation. β¨-activeforegroundcolor β sets the foreground color of active buttons. Same deal β it's active when the mouse passes over it or by thebutton activateoperation.-backgroundcolor β sets the background of the button. Default iswhite.-borderwidthpixels β sets the width of the 3-D border around the button. The-reliefoption decides whether a border gets drawn at all. Default is1.-closereliefrelief β the 3-D effect for the closed button. relief says how the button should appear relative to the widget; for example,raisedmeans the button should look like it's protruding. Default issolid.-cursorcursor β sets the widget's cursor. Default cursor is"".-foregroundcolor β sets the foreground color of buttons. Default isblack.-imagesimages β the images to display for the button. images is a list of two Tk images: the first shows when the button is open, the second when it's closed. If images is the empty string, then a plus/minus gadget gets drawn instead. Default is"". π«Ά-openreliefrelief β the 3-D effect of the open button. relief says how the button should appear relative to the widget; for example,raisedmeans it should look like it's protruding. Default isflat.-sizepixels β sets the requested size of the button. Default is0.
π COLUMN OPTIONS π
Column config options can also be set by the option command β resource subclass is Column, and the resource name is the name of the column.
option add *TreeView.Column.Foreground white
option add *TreeView.treeView.Background blue
Here's every config option available for columns π:
-backgroundcolor β sets the background color of the column. This overrides the widget's-backgroundoption. Default iswhite.-borderwidthpixels β sets the width of the 3-D border of the column. The-reliefoption decides whether a border gets drawn. Default is0.-editboolean β says whether the column's data fields can be edited. If boolean is false, the data fields in the column may not be edited. Default isyes.-foregroundcolor β the foreground color of the column. You can override this for individual entries with the entry's-foregroundoption. Default isblack.-fontfontName β sets the font for a column. You can override this for individual entries with the entry's-fontoption. Default is*-Helvetica-Bold-R-Normal-*-12-120-*. β-hideboolean β if boolean is true, the column isn't displayed. Default isyes.-justifyjustify β how the column data fields title should be justified within the column. This only matters when the column is wider than the data field being displayed. justify must beleft,right, orcenter. Default isleft.-padpad β how much padding for the left and right sides of the column. pad is a list of one or two screen distances. If pad has two elements, the left side of the column gets padded by the first distance and the right side by the second. If pad has just one distance, both the left and right sides get padded evenly. Default is2.-reliefrelief β the 3-D effect of the column. relief says how the column should appear relative to the widget; for example,raisedmeans the column should look like it's protruding. Default isflat.-statestate β sets the state of the column. If state isdisablethen the column title can't be activated nor invoked. Default isnormal.-textstring β sets the title for the column. Default is"".-titleforegroundcolor β sets the foreground color of the column title. Default isblack.-titleshadowcolor β sets the color of the drop shadow of the column title. Default is"". π¦-widthpixels β sets the requested width of the column. This overrides the computed width of the column. If pixels is0, the width is computed from the contents of the column. Default is0.
π TEXT EDITING OPTIONS π
Text edit window config options can also be set by the option command. Resource class is TreeViewEditor, and the resource name is always edit.
option add *TreeViewEditor.Foreground white
option add *edit.Background blue
Here's what's available for the text editing window, bestie:
-backgroundcolor β sets the background of the text edit window. Default iswhite.-borderwidthpixels β sets the width of the 3-D border around the edit window. The-reliefoption decides whether a border gets drawn. Default is1.-exportselectionboolean β says whether the text selection gets exported. If the edit window is exporting its selection, then it'll observe the standard X11 protocols for handling the selection. Selections are available as typeSTRING. Default isno.-reliefrelief β the 3-D effect of the edit window. relief says how the background should appear relative to the edit window; for example,raisedmeans the background should look like it's protruding. Default issolid.-selectbackgroundcolor β sets the background of the selected text in the edit window. Default iswhite.-selectborderwidthpixels β sets the width of the 3-D border around the selected text in the edit window. The-selectreliefoption decides whether a border gets drawn. Default is1.-selectforegroundcolor β sets the foreground of the selected text in the edit window. Default iswhite.-selectreliefrelief β the 3-D effect of the selected text in the edit window. relief says how the text should appear relative to the edit window; for example,raisedmeans the text should look like it's protruding. Default isflat. π
β¨ DEFAULT BINDINGS β¨
okay so boom β Tk just automatically makes class bindings for treeviews, and they give you that classic Motif-ish behavior π. and like, a huge chunk of how a treeview widget behaves is decided by its -selectmode option, which picks one of two ways of dealing with the selection.
if the selection mode is single, then bestieβ¦ only ONE node can be selected at a time. clicking button 1 on a node selects it and deselects any other selected item. that's it, that's the whole vibe π
.
if the selection mode is multiple, then any number of entries may be selected at once, including discontiguous ranges (yes, chaotic little ranges, we love that for you π). clicking Control+Button-1 on a node entry toggles its selection state without affecting any other entries. pressing Shift+Button-1 on a node entry selects it, and extends the selection. slay π«Ά.
- [1] in
extendedmode, the selected range can be adjusted by pressing button 1 with the Shift key down: this modifies the selection to consist of the entries between the anchor and the entry under the mouse, inclusive. the un-anchored end of this new selection can also be dragged with the button down. literally drag it, it drags β¨. - [2] in
extendedmode, pressing button 1 with the Control key down starts a toggle operation: the anchor is set to the entry under the mouse, and its selection state is reversed. the selection state of other entries isn't changed. if the mouse is dragged with button 1 down, then the selection state of all entries between the anchor and the entry under the mouse is set to match that of the anchor entry; the selection state of all other entries remains what it was before the toggle operation began. very demure, very "we only touch what we said we'd touch" π. - [3] if the mouse leaves the treeview window with button 1 down, the window scrolls away from the mouse, making information visible that used to be off-screen on the side of the mouse. the scrolling continues until the mouse re-enters the window, the button is released, or the end of the hierarchy is reached. it just keeps going π.
- [4] mouse button 2 may be used for scanning. if it is pressed and dragged over the treeview widget, the contents of the hierarchy drag at high speed in the direction the mouse moves. zoom zoom π₯.
- [5] if the Up or Down key is pressed, the location cursor (active entry) moves up or down one entry. if the selection mode is
browseorextendedthen the new active entry is also selected and all other entries are deselected. inextendedmode the new active entry becomes the selection anchor. π - [6] in
extendedmode, Shift+Up and Shift+Down move the location cursor (active entry) up or down one entry and also extend the selection to that entry in a fashion similar to dragging with mouse button 1. - [7] the Left and Right keys scroll the treeview widget view left and right by the width of the character
0. Control+Left and Control+Right scroll the treeview widget view left and right by the width of the window. Control+Prior and Control+Next also scroll left and right by the width of the window. yes, a whole window's worth, hold on tight π¦. - [8] the Prior and Next keys scroll the treeview widget view up and down by one page (the height of the window).
- [9] the Home and End keys scroll the treeview widget horizontally to the left and right edges, respectively.
- [10] Control+Home sets the location cursor to the first entry, selects that entry, and deselects everything else in the widget. clean slate energy β¨.
- [11] Control+End sets the location cursor to the last entry, selects that entry, and deselects everything else in the widget.
- [12] in
extendedmode, Control+Shift+Home extends the selection to the first entry and Control+Shift+End extends the selection to the last entry. - [13] in
multiplemode, Control+Shift+Home moves the location cursor to the first entry and Control+Shift+End moves the location cursor to the last entry. note the difference bestie β cursor moves, selection does not change. iykyk π . - [14] the space and Select keys make a selection at the location cursor (active entry) just as if mouse button 1 had been pressed over this entry.
- [15] in
extendedmode, Control+Shift+space and Shift+Select extend the selection to the active entry just as if button 1 had been pressed with the Shift key down. - [16] in
extendedmode, the Escape key cancels the most recent selection and restores all the entries in the selected range to their previous selection state. undo button but make it keyboard π§. - [17] Control+slash selects everything in the widget, except in
singleandbrowsemodes, in which case it selects the active entry and deselects everything else. - [18] Control+backslash deselects everything in the widget, except in
browsemode where it has no effect. absolutely nothing happens there, don't fight it π. - [19] the F16 key (labelled Copy on many Sun workstations) or Meta+w copies the selection in the widget to the clipboard, if there is a selection.
the behavior of treeview widgets can be changed by defining new bindings for individual widgets or by redefining the class bindings. your treeview, your rules π.
πΈ WIDGET BINDINGS πΈ
in addition to the above behavior, the following additional behavior is defined by the default widget class (TreeView) bindings.
<ButtonPress-2>β starts scanning.<B2-Motion>β adjusts the scan.<ButtonRelease-2>β stops scanning.<B1-Leave>β starts auto-scrolling.<B1-Enter>β starts auto-scrolling<KeyPress-Up>β moves the focus to the previous entry.<KeyPress-Down>β moves the focus to the next entry.<Shift-KeyPress-Up>β moves the focus to the previous sibling.<Shift-KeyPress-Down>β moves the focus to the next sibling.<KeyPress-Prior>β moves the focus to first entry. closed or hidden entries are ignored.<KeyPress-Next>β move the focus to the last entry. closed or hidden entries are ignored.<KeyPress-Left>β closes the entry. it is not an error if the entry has no children. no drama, no crash π .<KeyPress-Right>β opens the entry, displaying its children. it is not an error if the entry has no children.<KeyPress-space>β in"single"select mode this selects the entry. in"multiple"mode, it toggles the entry (if it was previous selected, it is not deselected).<KeyRelease-space>β turns off select mode.<KeyPress-Return>β sets the focus to the current entry.<KeyRelease-Return>β turns off select mode.<KeyPress>β moves to the next entry whose label starts with the letter typed. type-to-find, iconic behavior tbh β.<KeyPress-Home>β moves the focus to first entry. closed or hidden entries are ignored.<KeyPress-End>β move the focus to the last entry. closed or hidden entries are ignored.<KeyPress-F1>β opens all entries.<KeyPress-F2>β closes all entries (except root).
π¦ BUTTON BINDINGS π¦
buttons have bindings. there are associated with the "all" bindtag (see the entry's -bindtag option). you can use the bind operation to change them.
<Enter>β highlights the button of the current entry.<Leave>β returns the button back to its normal state.<ButtonRelease-1>β adjust the view so that the current entry is visible.
π ENTRY BINDINGS π
entries have default bindings. there are associated with the "all" bindtag (see the entry's -bindtag option). you can use the bind operation to modify them.
<Enter>β highlights the current entry.<Leave>β returns the entry back to its normal state.<ButtonPress-1>β sets the selection anchor the current entry.<Double-ButtonPress-1>β toggles the selection of the current entry.<B1-Motion>β for"multiple"mode only. saves the current location of the pointer for auto-scrolling. resets the selection mark.<ButtonRelease-1>β for"multiple"mode only. sets the selection anchor to the current entry.<Shift-ButtonPress-1>β for"multiple"mode only. extends the selection.<Shift-Double-ButtonPress-1>β place holder. does nothing. literally nothing, bestie π.<Shift-B1-Motion>β place holder. does nothing.<Shift-ButtonRelease-1>β stop auto-scrolling.<Control-ButtonPress-1>β for"multiple"mode only. toggles and extends the selection.<Control-Double-ButtonPress-1>β place holder. does nothing.<Control-B1-Motion>β place holder. does nothing.<Control-ButtonRelease-1>β stops auto-scrolling.<Control-Shift-ButtonPress-1>β???(that's genuinely what the docs say, bestie β not me, i'm just the messenger π)<Control-Shift-Double-ButtonPress-1>β place holder. does nothing.<Control-Shift-B1-Motion>β place holder. does nothing.
π COLUMN BINDINGS π
columns have bindings too. they are associated with the column's "all" bindtag (see the column -bindtag option). you can use the column bind operation to change them.
<Enter>β highlights the current column title.<Leave>β returns the column back to its normal state.<ButtonRelease-1>β invokes the command (see the column's-commandoption) if one if specified.
π COLUMN RULE BINDINGS π
<Enter>β highlights the current and activates the ruler.<Leave>β returns the column back to its normal state. deactivates the ruler.<ButtonPress-1>β sets the resize anchor for the column.<B1-Motion>β sets the resize mark for the column.<ButtonRelease-1>β adjust the size of the column, based upon the resize anchor and mark positions.
resize anchor + resize mark = column glow-up, no cap πβ¨
πΈ EXAMPLE πΈ
okay so the treeview command creates a new widget, like this:
treeview .h -bg white
A new Tcl command .h is also created. This command can be used to query and modify the treeview widget. For example, to change the background color of the table to "green", you use the new command and the widget's configure operation.
# Change the background color.
.h configure -background "green"
By default, the treeview widget will automatically create a new tree object to contain the data. The name of the new tree is the pathname of the widget. Above, the new tree object name is ".h". But you can use the -tree option to specify the name of another tree.
# View the tree "myTree".
.h configure -tree "myTree"
When a new tree is created, it contains only a root node. The node is automatically opened. The id of the root node is always 0 (you can also use the special id root). The insert operation lets you insert one or more new entries into the tree. The last argument is the node's pathname.
# Create a new entry named "myEntry"
set id [.h insert end "myEntry"]
This appends a new node named "myEntry". It will be positioned as the last child of the root of the tree (using the position "end"). You can supply another position to order the node within its siblings.
# Prepend "fred".
set id [.h insert 0 "fred"]
Entry names do not need to be unique. By default, the node's label is its name. To supply a different text label, add the -label option.
# Create a new node named "fred"
set id [.h insert end "fred" -label "Fred Flintstone"]
The insert operation returns the id of the new node. You can also use the index operation to get this information.
# Get the id of "fred"
.h index "fred"
To insert a node somewhere other than root, use the -at switch. It takes the id of the node where the new child will be added.
# Create a new node "barney" in "fred".
.h insert -at $id end "barney"
A pathname describes the path to an entry in the hierarchy. It's a list of entry names that compose the path in the tree. Therefore, you can also add "barney" to "fred" as follows.
# Create a new sub-entry of "fred"
.h insert end "fred barney"
Every name in the list is an ancestor of the next. All ancestors must already exist. That means that an entry "fred" is an ancestor of "barney" and must already exist. But you can use the -autocreate configuration option to force the creation of ancestor nodes.
# Force the creation of ancestors.
.h configure -autocreate yes
.h insert end "fred barney wilma betty"
Sometimes the pathname is already separated by a character sequence rather than formed as a list. A file name is a good example of this. You can use the -separator option to specify a separator string to split the path into its components. Each pathname inserted is automatically split using the separator string as a separator. Multiple separators are treated as one.
.h configure -separator /
.h insert end "/usr/local/tcl/bin"
If the path is prefixed by extraneous characters, you can automatically trim it off using the -trim option. It removes the string from the path before it is parsed.
.h configure -trim C:/windows -separator /
.h insert end "C:/window/system"
You can insert more than one entry at a time with the insert operation. This can be much faster than looping over a list of names.
# The slow way
foreach f [glob $dir/*] {
.h insert end $f
}
# The fast way
eval .h insert end [glob $dir/*]
In this case, the insert operation will return a list of ids of the new entries.
You can delete entries with the delete operation. It takes one or more tags of ids as its argument. It deletes the entry and all its children.
.h delete $id
Entries have several configuration options. They control the appearance of the entry's icon and label. We have already seen the -label option that sets the entry's text label. The entry configure operation lets you set or modify an entry's configuration options.
.h entry configure $id -color red -font fixed
You can hide an entry and its children using the -hide option.
.h entry configure $id -hide yes
More than one entry can be configured at once. All entries specified are configured with the same options.
.h entry configure $i1 $i2 $i3 $i4 -color brown
An icon is displayed for each entry. It's a Tk image drawn to the left of the label. You can set the icon with the entry's -icons option. It takes a list of two image names: one to represent the open entry, another when it is closed.
set im1 [image create photo -file openfolder.gif]
set im2 [image create photo -file closefolder.gif]
.h entry configure $id -icons "$im1 $im2"
If -icons is set to the empty string, no icons are displayed.
If an entry has children, a button is displayed to the left of the icon. Clicking the mouse on this button opens or closes the sub-hierarchy. The button is normally a + or - symbol, but can be configured in a variety of ways using the button configure operation. For example, the + and - symbols can be replaced with Tk images.
set im1 [image create photo -file closefolder.gif]
set im2 [image create photo -file downarrow.gif]
.h button configure $id -images "$im1 $im2" \
-openrelief raised -closerelief raised
Entries can contain an arbitrary number of data fields. Data fields are name-value pairs. Both the value and name are strings. The entry's -data option lets you set data fields.
.h entry configure $id -data {mode 0666 group users}
The -data takes a list of name-value pairs.
You can display these data fields as columns in the treeview widget. You can create and configure columns with the column operation. For example, to add a new column to the widget, use the column insert operation. The last argument is the name of the data field that you want to display.
.h column insert end "mode"
The column title is displayed at the top of the column. By default, it's the field name. You can override this using the column's -text option.
.h column insert end "mode" -text "File Permissions"
Columns have several configuration options. The column configure operation lets you query or modify column options.
.h column configure "mode" -justify left
The -justify option says how the data is justified within the column. The -hide option indicates whether the column is displayed.
.h column configure "mode" -hide yes
Entries can be selected by clicking on the mouse. Selected entries are drawn using the colors specified by the -selectforeground and -selectbackground configuration options. The selection itself is managed by the selection operation.
# Clear all selections
.h selection clear 0 end
# Select the root node
.h selection set 0
The curselection operation returns a list of ids of all the selected entries.
set ids [.h curselection]
You can use the get operation to convert the ids to their pathnames.
set names [eval .h get -full $ids]
If a treeview is exporting its selection (using the -exportselection option), then it will observe the standard X11 protocols for handling the selection. Treeview selections are available as type STRING; the value of the selection will be the pathnames of the selected entries, separated by newlines.
The treeview supports two modes of selection: single and multiple. In single select mode, only one entry can be selected at a time, while multiple select mode allows several entries to be selected. The mode is set by the widget's -selectmode option.
.h configure -selectmode "multiple"
You can be notified when the list of selected entries changes. The widget's -selectcommand specifies a Tcl procedure that is called whenever the selection changes.
proc SelectNotify { widget } {
set ids [$widget curselection]
}
.h configure -selectcommand "SelectNotify .h"
The widget supports the standard Tk scrolling and scanning operations. The treeview can be both horizontally and vertically. You can attach scrollbars to the treeview the same way as the listbox or canvas widgets.
scrollbar .xbar -orient horizontal -command ".h xview"
scrollbar .ybar -orient vertical -command ".h yview"
.h configure -xscrollcommand ".xbar set" \
-yscrollcommand ".ybar set"
There are three different modes of scrolling: listbox, canvas, and hierbox. In listbox mode, the last entry can always be scrolled to the top of the widget. In hierbox mode, the last entry is always drawn at the bottom of the widget. The scroll mode is set by the widget's -selectmode option.
heads up bestie: the page literally says-selectmodethere, but the example right below sets-scrollmode. that's the manual being the manual π
.h configure -scrollmode "listbox"
Entries can be programmatically opened or closed using the open and close operations respectively.
.h open $id
.h close $id
When an entry is opened, a Tcl procedure can be automatically invoked. The -opencommand option specifies this procedure. This procedure can lazily insert entries as needed.
proc AddEntries { dir } {
eval .h insert end [glob -nocomplain $dir/*]
}
.h configure -opencommand "AddEntries %P"
Now when an entry is opened, the procedure AddEntries is called and adds children to the entry. Before the command is invoked, special "%" substitutions (like bind) are performed. Above, %P is translated to the pathname of the entry.
The same feature exists when an entry is closed. The -closecommand option specifies the procedure.
proc DeleteEntries { id } {
.h entry delete $id 0 end
}
.h configure -closecommand "DeleteEntries %#"
When an entry is closed, the procedure DeleteEntries is called and deletes the entry's children using the entry delete operation (%# is the id of entry).
π KEYWORDS π
treeviewwidget
and that's the whole treeview(n) page, bestie π
β¨ source is BLT, version 2.5, page treeview(n) β that's the footer energy, no separate calendar date on this one, just the source/version and the page name. mwah π«Άπ
π¦ where this page comes from
- nixpkgs unstable: blt 2.5.3
- Copyright 2001-2 by Silicon Metrics Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms