class Table(object): (source)
Constructor: Table(master, column_names, rows, column_weights, ...)
A display widget for a table of values, based on a MultiListbox widget. For many purposes, Table can be treated as a list-of-lists. E.g., table[i] is a list of the values for row i; and table.append(row) adds a new row with the given lits of values. Individual cells can be accessed using table[i,j], which refers to the j-th column of the i-th row. This can be used to both read and write values from the table. E.g.:
>>> table[i,j] = 'hello'
The column (j) can be given either as an index number, or as a column name. E.g., the following prints the value in the 3rd row for the 'First Name' column:
>>> print(table[3, 'First Name']) John
You can configure the colors for individual rows, columns, or cells using rowconfig(), columnconfig(), and itemconfig(). The color configuration for each row will be preserved if the table is modified; however, when new rows are added, any color configurations that have been made for columns will not be applied to the new row.
Note: Although Table acts like a widget in some ways (e.g., it defines grid(), pack(), and bind()), it is not itself a widget; it just contains one. This is because widgets need to define __getitem__(), __setitem__(), and __nonzero__() in a way that's incompatible with the fact that Table behaves as a list-of-lists.
Method | __delitem__ |
Delete the ``row_index``th row from this table. |
Method | __getitem__ |
Broken description |
Method | __init__ |
Construct a new Table widget. |
Method | __len__ |
No summary |
Method | __setitem__ |
Replace the value of a row or a cell in this table with val. |
Method | append |
Add a new row to the end of the table. |
Method | bind |
Add a binding to this table's main frame that will call func in response to the event sequence. |
Method | bind |
No summary |
Method | bind |
No summary |
Method | bind |
No summary |
Method | clear |
Delete all rows in this table. |
Method | column |
If i is a valid column index integer, then return it as is. Otherwise, check if i is used as the name for any column; if so, return that column's index. Otherwise, raise a KeyError exception. |
Method | columnconfigure |
No summary |
Method | extend |
Add new rows at the end of the table. |
Method | focus |
Direct (keyboard) input foxus to this widget. |
Method | grid |
Position this table's main frame widget in its parent widget. See Tkinter.Frame.grid() for more info. |
Method | hide |
No summary |
Method | insert |
Insert a new row into the table, so that its row index will be row_index. If the table contains any rows whose row index is greater than or equal to row_index, then they will be shifted down. |
Method | itemconfigure |
No summary |
Method | pack |
Position this table's main frame widget in its parent widget. See Tkinter.Frame.pack() for more info. |
Method | rowconfigure |
No summary |
Method | select |
No summary |
Method | selected |
Return the index of the currently selected row, or None if no row is selected. To get the row value itself, use table[table.selected_row()]. |
Method | show |
No summary |
Method | sort |
Sort the rows in this table, using the specified column's values as a sort key. |
Property | column |
A list of the names of the columns in this table. |
Method | _check |
Verify that the contents of the table's _rows variable match the contents of its multi-listbox (_mlb). This is just included for debugging purposes, to make sure that the list-modifying operations are working correctly. |
Method | _checkrow |
Helper function: check that a given row value has the correct number of elements; and if not, raise an exception. |
Method | _fill |
Re-draw the table from scratch, by clearing out the table's multi-column listbox; and then filling it in with values from self._rows. Note that any cell-, row-, or column-specific color configuration that has been done will be lost... |
Method | _get |
Undocumented |
Method | _restore |
Restore selection & color configuration information that was saved using _save_config_info. |
Method | _save |
Return a 'cookie' containing information about which row is selected, and what color configurations have been applied. this information can the be re-applied to the table (after making modifications) using ... |
Method | _sort |
Event handler for clicking on a column label -- sort by that column. |
Constant | _DEBUG |
If true, then run _check_table_vs_mlb() after any operation that modifies the table. |
Instance Variable | _column |
Undocumented |
Instance Variable | _frame |
Undocumented |
Instance Variable | _mlb |
The multi-column listbox used to display this table's data. |
Instance Variable | _num |
Undocumented |
Instance Variable | _reprfunc |
Undocumented |
Instance Variable | _rows |
A list-of-lists used to hold the cell values of this table. Each element of _rows is a row value, i.e., a list of cell values, one for each column in the row. |
Instance Variable | _scrollbar |
Undocumented |
Instance Variable | _sortkey |
Undocumented |
Return the value of a row or a cell in this table. If ``index`` is an integer, then the row value for the ``index``th row. This row value consists of a tuple of cell values, one for each column in the row. If ``index`` is a tuple of two integers, ``(i,j)``, then return the value of the cell in the ``i``th row and the ``j``th column.
Construct a new Table widget.
Parameters | |
master:Tkinter.Widget | The widget that should contain the new table. |
column | A list of names for the columns; these names will be used to create labels for each column; and can be used as an index when reading or writing cell values from the table. |
rows:list(list) | A list of row values used to initialze the table. Each row value should be a tuple of cell values, one for each column in the row. |
column | Undocumented |
scrollbar:bool | If true, then create a scrollbar for the new table widget. |
click | If true, then create bindings that will sort the table's rows by a given column's values if the user clicks on that colum's label. |
reprfunc:function | If specified, then use this function to convert each table cell value to a string suitable for display. reprfunc has the following signature: reprfunc(row_index, col_index, cell_value) -> str (Note that the column is specified by index, not by name.) |
cnf | Undocumented |
cnf, kw | Configuration parameters for this widget's contained MultiListbox. See MultiListbox.__init__() for details. |
**kw | Undocumented |
Replace the value of a row or a cell in this table with val.
If index is an integer, then val should be a row value (i.e., a tuple of cell values, one for each column). In this case, the values of the index``th row of the table will be replaced with the values in ``val.
If index is a tuple of integers, (i,j), then replace the value of the cell in the i``th row and ``j``th column with ``val.
Add a new row to the end of the table.
Parameters | |
rowvalue | A tuple of cell values, one for each column in the new row. |
If i is a valid column index integer, then return it as is. Otherwise, check if i is used as the name for any column; if so, return that column's index. Otherwise, raise a KeyError exception.
Add new rows at the end of the table.
Parameters | |
rowvalues | A list of row values used to initialze the table. Each row value should be a tuple of cell values, one for each column in the row. |
Position this table's main frame widget in its parent widget. See Tkinter.Frame.grid() for more info.
Insert a new row into the table, so that its row index will be row_index. If the table contains any rows whose row index is greater than or equal to row_index, then they will be shifted down.
Parameters | |
row | Undocumented |
rowvalue | A tuple of cell values, one for each column in the new row. |
Position this table's main frame widget in its parent widget. See Tkinter.Frame.pack() for more info.
Return the index of the currently selected row, or None if no row is selected. To get the row value itself, use table[table.selected_row()].
Sort the rows in this table, using the specified column's values as a sort key.
Parameters | |
column | Specifies which column to sort, using either a column index (int) or a column's label name (str). |
order | Specifies whether to sort the values in ascending or descending order:
|
Verify that the contents of the table's _rows variable match the contents of its multi-listbox (_mlb). This is just included for debugging purposes, to make sure that the list-modifying operations are working correctly.
Helper function: check that a given row value has the correct number of elements; and if not, raise an exception.
Re-draw the table from scratch, by clearing out the table's multi-column listbox; and then filling it in with values from self._rows. Note that any cell-, row-, or column-specific color configuration that has been done will be lost. The selection will also be lost -- i.e., no row will be selected after this call completes.
Return a 'cookie' containing information about which row is selected, and what color configurations have been applied. this information can the be re-applied to the table (after making modifications) using _restore_config_info(). Color configuration information will be saved for any rows in row_indices, or in the entire table, if row_indices=None. If index_by_id=True, the the cookie will associate rows with their configuration information based on the rows' python id. This is useful when performing operations that re-arrange the rows (e.g. sort). If index_by_id=False, then it is assumed that all rows will be in the same order when _restore_config_info() is called.