Table¶
-
class
ttkwidgets.
Table
(master=None, show='headings', drag_cols=True, drag_rows=True, sortable=True, class_='Table', **kwargs)[source]¶ Bases:
ttk.Treeview
Table widget displays a table with options to drag rows and columns and to sort columns.
This widget is based on the
ttk.Treeview
and shares many options and methods with it.-
__init__
(master=None, show='headings', drag_cols=True, drag_rows=True, sortable=True, class_='Table', **kwargs)[source]¶ Create a Table.
Parameters: - master (widget) – master widget
- drag_cols (bool) – whether columns are draggable
- drag_rows (bool) – whether rows are draggable
- sortable (bool) – whether columns are sortable by clicking on their headings. The sorting order depends on the type of data (str, float, …) which can be set with the column method.
- show (str) – which parts of the treeview to show (same as the Treeview option)
- kwargs – options to be passed on to the
ttk.Treeview
initializer
-
cget
(key)[source]¶ Query widget option.
Parameters: key (str) – option name Returns: value of the option To get the list of options for this widget, call the method
keys()
.
-
column
(column, option=None, **kw)[source]¶ Query or modify the options for the specified column.
If kw is not given, returns a dict of the column option values. If option is specified then the value for that option is returned. Otherwise, sets the options to the corresponding values.
Parameters: - id – the column’s identifier (read-only option)
- anchor – “n”, “ne”, “e”, “se”, “s”, “sw”, “w”, “nw”, or “center”: alignment of the text in this column with respect to the cell
- minwidth (int) – minimum width of the column in pixels
- stretch (bool) – whether the column’s width should be adjusted when the widget is resized
- width (int) – width of the column in pixels
- type (type) – column’s content type (for sorting), default type is str
-
configure
(cnf=None, **kw)[source]¶ Configure resources of the widget.
To get the list of options for this widget, call the method
keys()
. See__init__()
for a description of the widget specific option.
-
delete
(*items)[source]¶ Delete all specified items and all their descendants. The root item may not be deleted.
Parameters: items (sequence[str]) – list of item identifiers
-
detach
(*items)[source]¶ Unlinks all of the specified items from the tree.
The items and all of their descendants are still present, and may be reinserted at another point in the tree, but will not be displayed. The root item may not be detached.
Parameters: items (sequence[str]) – list of item identifiers
-
heading
(column, option=None, **kw)[source]¶ Query or modify the heading options for the specified column.
If kw is not given, returns a dict of the heading option values. If option is specified then the value for that option is returned. Otherwise, sets the options to the corresponding values.
Parameters: - text (str) – text to display in the column heading
- image (PhotoImage) – image to display to the right of the column heading
- anchor (str) – “n”, “ne”, “e”, “se”, “s”, “sw”, “w”, “nw”, or “center”: alignement of the heading text
- command (function) – callback to be invoked when the heading label is pressed.
-
insert
(parent, index, iid=None, **kw)[source]¶ Creates a new item and return the item identifier of the newly created item.
Parameters: - parent (str) – identifier of the parent item
- index (int or "end") – where in the list of parent’s children to insert the new item
- iid (None or str) – item identifier, iid must not already exist in the tree. If iid is None a new unique identifier is generated.
- kw – item’s options: see
item()
Returns: the item identifier of the newly created item
Return type: str
-
item
(item, option=None, **kw)[source]¶ Query or modify the options for the specified item.
If no options are given, a dict with options/values for the item is returned. If option is specified then the value for that option is returned. Otherwise, sets the options to the corresponding values as given by kw.
Parameters: - text (str) – item’s label
- image (PhotoImage) – image to be displayed on the left of the item’s label
- values (sequence) – values to put in the columns
- open (bool) – whether the item’s children should be displayed
- tags (sequence[str]) – list of tags associated with this item
-
move
(item, parent, index)[source]¶ Moves item to position index in parent’s list of children.
It is illegal to move an item under one of its descendants. If index is less than or equal to zero, item is moved to the beginning, if greater than or equal to the number of children, it is moved to the end. If item was detached it is reattached.
Parameters: - item (str) – item’s identifier
- parent (str) – new parent of item
- index (int of "end") – where in the list of parent’s children to insert item
-
reattach
(item, parent, index)¶ Moves item to position index in parent’s list of children.
It is illegal to move an item under one of its descendants. If index is less than or equal to zero, item is moved to the beginning, if greater than or equal to the number of children, it is moved to the end. If item was detached it is reattached.
Parameters: - item (str) – item’s identifier
- parent (str) – new parent of item
- index (int of "end") – where in the list of parent’s children to insert item
-
set
(item, column=None, value=None)[source]¶ Query or set the value of given item.
With one argument, return a dictionary of column/value pairs for the specified item. With two arguments, return the current value of the specified column. With three arguments, set the value of given column in given item to the specified value.
Parameters: - item (str) – item’s identifier
- column (str, int or None) – column’s identifier
- value – new value
-
set_children
(item, *newchildren)[source]¶ Replaces item’s children with newchildren.
Children present in item that are not present in newchildren are detached from tree. No items in newchildren may be an ancestor of item.
Parameters: newchildren (sequence[str]) – new item’s children (list of item identifiers)
-