class documentation

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_to_columns No summary
Method bind_to_labels No summary
Method bind_to_listboxes No summary
Method clear Delete all rows in this table.
Method column_index 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_column 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_row 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_column No summary
Method sort_by Sort the rows in this table, using the specified column's values as a sort key.
Property column_names A list of the names of the columns in this table.
Method _check_table_vs_mlb 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_table 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_itemconfig Undocumented
Method _restore_config_info Restore selection & color configuration information that was saved using _save_config_info.
Method _save_config_info 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_name_to_index Undocumented
Instance Variable _frame Undocumented
Instance Variable _mlb The multi-column listbox used to display this table's data.
Instance Variable _num_columns 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
def __delitem__(self, row_index): (source)

Delete the ``row_index``th row from this table.

def __getitem__(self, index): (source)

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.

def __init__(self, master, column_names, rows=None, column_weights=None, scrollbar=True, click_to_sort=True, reprfunc=None, cnf={}, **kw): (source)

Construct a new Table widget.

Parameters
master:Tkinter.WidgetThe widget that should contain the new table.
column_names:list(str)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_weightsUndocumented
scrollbar:boolIf true, then create a scrollbar for the new table widget.
click_to_sort:boolIf 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:functionIf 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.)
cnfUndocumented
cnf, kwConfiguration parameters for this widget's contained MultiListbox. See MultiListbox.__init__() for details.
**kwUndocumented
def __len__(self): (source)
Returns
the number of rows in this table.
def __setitem__(self, index, val): (source)

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.

def append(self, rowvalue): (source)

Add a new row to the end of the table.

Parameters
rowvalueA tuple of cell values, one for each column in the new row.
def bind(self, sequence=None, func=None, add=None): (source)

Add a binding to this table's main frame that will call func in response to the event sequence.

def bind_to_columns(self, sequence=None, func=None, add=None): (source)
See Also
MultiListbox.bind_to_columns()
def bind_to_labels(self, sequence=None, func=None, add=None): (source)
See Also
MultiListbox.bind_to_labels()
def bind_to_listboxes(self, sequence=None, func=None, add=None): (source)
See Also
MultiListbox.bind_to_listboxes()
def clear(self): (source)

Delete all rows in this table.

def column_index(self, i): (source)

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.

def columnconfigure(self, col_index, cnf={}, **kw): (source)
See Also
MultiListbox.columnconfigure()
def extend(self, rowvalues): (source)

Add new rows at the end of the table.

Parameters
rowvaluesA 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.
def focus(self): (source)

Direct (keyboard) input foxus to this widget.

def grid(self, *args, **kwargs): (source)

Position this table's main frame widget in its parent widget. See Tkinter.Frame.grid() for more info.

def hide_column(self, column_index): (source)
See Also
MultiListbox.hide_column()
def insert(self, row_index, rowvalue): (source)

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_indexUndocumented
rowvalueA tuple of cell values, one for each column in the new row.
def itemconfigure(self, row_index, col_index, cnf=None, **kw): (source)
See Also
MultiListbox.itemconfigure()
def pack(self, *args, **kwargs): (source)

Position this table's main frame widget in its parent widget. See Tkinter.Frame.pack() for more info.

def rowconfigure(self, row_index, cnf={}, **kw): (source)
See Also
MultiListbox.rowconfigure()
def select(self, index=None, delta=None, see=True): (source)
See Also
MultiListbox.select()
def selected_row(self): (source)

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()].

def show_column(self, column_index): (source)
See Also
MultiListbox.show_column()
def sort_by(self, column_index, order='toggle'): (source)

Sort the rows in this table, using the specified column's values as a sort key.

Parameters
column_indexSpecifies 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:

  • 'ascending': Sort from least to greatest.
  • 'descending': Sort from greatest to least.
  • 'toggle': If the most recent call to sort_by() sorted the table by the same column (column_index), then reverse the rows; otherwise sort in ascending order.
@property
column_names = (source)

A list of the names of the columns in this table.

def _check_table_vs_mlb(self): (source)

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.

def _checkrow(self, rowvalue): (source)

Helper function: check that a given row value has the correct number of elements; and if not, raise an exception.

def _fill_table(self, save_config=True): (source)

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.

def _get_itemconfig(self, r, c): (source)

Undocumented

def _restore_config_info(self, cookie, index_by_id=False, see=False): (source)

Restore selection & color configuration information that was saved using _save_config_info.

def _save_config_info(self, row_indices=None, index_by_id=False): (source)

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.

def _sort(self, event): (source)

Event handler for clicking on a column label -- sort by that column.

_DEBUG: bool = (source)

If true, then run _check_table_vs_mlb() after any operation that modifies the table.

Value
False
_column_name_to_index = (source)

Undocumented

Undocumented

The multi-column listbox used to display this table's data.

_num_columns = (source)

Undocumented

_reprfunc = (source)

Undocumented

_rows: list = (source)

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.

_scrollbar = (source)

Undocumented

_sortkey = (source)

Undocumented