tktable.table¶
The Table widget, a Python wrapper of the Tcl/Tk Tktable widget.
- tktable.table.TableIndex¶
A table index: “row,col” (e.g. “2,3”), or a special one such as “active”, “anchor”, “end”, “origin”, “topleft”, “bottomright” or “@x,y” (the cell at pixel x,y).
- exception tktable.table.CannotUseError[source]¶
Bases:
RuntimeErrorThe exception raised when you cannot use the Table because of missing dependencies.
- class tktable.table.TableEvent[source]¶
Bases:
EventThe event given to the callbacks of a Table (browsecommand, command, validatecommand, …).
Its attributes are Tktable’s %-substitutions.
- class tktable.table.Table(master=None, **kw)[source]¶
Bases:
WidgetA table (spreadsheet-like) widget.
The keyword arguments are the options of the Tktable widget, without the leading “-”, e.g.
Table(root, rows=10, cols=5, variable=array_var).- Raises:
CannotUseError – if Tktable cannot be loaded.
- Parameters:
- activate(index)[source]¶
Set the active cell to the one indicated by index.
- Parameters:
index (str)
- Return type:
None
- bbox(first, last=None)[source]¶
Return the bounding box for the specified cell (range) as a 4-tuple of x, y, width and height in pixels. It clips the box to the visible portion, if any, otherwise an empty tuple is returned.
- clear(option, first=None, last=None)[source]¶
This is a convenience routine to clear certain state information managed by the table. first and last represent valid table indices. If neither are specified, then the command operates on the whole table.
- clear_cache(first=None, last=None)[source]¶
Clear the specified section of the cache, if the table has been keeping one.
- clear_sizes(first=None, last=None)[source]¶
Clear the specified row and column areas of specific height/width dimensions. When just one index is specified, for example 2,0, that is interpreted as row 2 and column 0.
- clear_tags(first=None, last=None)[source]¶
Clear the specified area of tags (all row, column and cell tags).
- clear_all(first=None, last=None)[source]¶
Perform all of the above clear functions on the specified area.
- curselection(value=None)[source]¶
With no arguments, it returns the sorted indices of the currently selected cells. Otherwise it sets all the selected cells to the given value if there is an associated ArrayVar and the state is not disabled.
- curvalue(value=None)[source]¶
If no value is given, the value of the cell being edited (indexed by active) is returned, else it is set to the given value.
- delete_active(index1, index2=None)[source]¶
Deletes text from the active cell. If only one index is given, it deletes the character after that index, otherwise it deletes from the first index to the second. index can be a number, insert or end.
- delete_cols(index, count=None, switches=None)[source]¶
Delete count columns (1 by default) starting at column index.
- delete_rows(index, count=None, switches=None)[source]¶
Delete count rows (1 by default) starting at row index.
- get(first, last=None)[source]¶
Returns the value of the cells specified by the table indices first and (optionally) last.
- height(row=None, **kwargs)[source]¶
If row and kwargs are not given, a dict describing all rows for which a height has been set is returned. If row is given, the height of that row is returned. If kwargs is given, then it sets the key/value pairs, where key is a row and value represents the height for the row.
When called without args, it returns all the hidden cells (those cells covered by a spanning cell). If one index is specified, it returns the spanning cell covering that index, if any. If multiple indices are specified, it returns 1 if all indices are hidden cells, 0 otherwise.
- icursor(arg=None)[source]¶
If arg is not specified, return the location of the insertion cursor in the active cell. Otherwise, set the cursor to that point in the string.
0 is before the first character, you can also use insert or end for the current insertion point or the end of the text. If there is no active cell, or the cell or table is disabled, this will return -1.
- index(index, rc=None)[source]¶
Return the integer cell coordinate that corresponds to index in the form row, col. If rc is specified, it must be either ‘row’ or ‘col’ so only the row or column index is returned.
- insert_active(index, value)[source]¶
The value is a text string which is inserted at the index position of the active cell. The cursor is then positioned after the new text. index can be a number, insert or end.
- insert_cols(index, count=None, switches=None)[source]¶
Insert count columns (1 by default) after column index.
- insert_rows(index, count=None, switches=None)[source]¶
Insert count rows (1 by default) after row index.
- reread()[source]¶
Rereads the old contents of the cell back into the editing buffer. Useful for a key binding when <Escape> is pressed to abort the edit (a default binding).
- Return type:
None
- scan_dragto(x, y)[source]¶
Scroll the view by 10 times the distance between x,y and the last scan_mark().
- see(index)[source]¶
Scroll the view so that the cell index is visible.
- Parameters:
index (str)
- Return type:
None
- selection_anchor(index)[source]¶
Set the selection anchor to the cell index.
- Parameters:
index (str)
- Return type:
None
- selection_clear(first, last=None)[source]¶
Deselect the cells from first to last; first can be “all”.
- set(*args, rc=None, index=None, **kwargs)[source]¶
If rc is specified (either ‘row’ or ‘col’) then it is assumes that args (if given) represents values which will be set into the subsequent columns (if row is specified) or rows (for col). If index is not None and args is not given, then it will return the value(s) for the cell(s) specified.
If kwargs is given, assumes that each key in kwargs is a index in this table and sets the specified index to the associated value. Table validation will not be triggered via this method.
Note that the table must have an associated array (defined through the variable option) in order to this work.
- spans(index=None, **kwargs)[source]¶
Manipulate row/col spans.
When called with no arguments, all known spans are returned as a dict. When called with only the index, the span for that index only is returned, if any. Otherwise kwargs is assumed to contain keys/values pairs used to set spans. A span starts at the row,col defined by a key and continues for the specified number of rows,cols specified by its value. A span of 0,0 unsets any span on that cell.
- tag_cell(tagname, *args)[source]¶
Apply the tag to the given cells, or return the cells with the tag.
- tag_col(tagname, *args)[source]¶
Apply the tag to the given columns, or return the columns with the tag.
- tag_configure(tagname, option=None, **kwargs)[source]¶
Query or modify options associated with the tag given by tagname.
If no option is specified, a dict describing all of the available options for tagname is returned. If option is specified, then the command returns a list describing the one named option. Lastly, if kwargs is given then it corresponds to option-value pairs that should be modified.
- tag_lower(tagname, belowthis=None)[source]¶
Lower the tag’s priority below the tag belowthis, or to the lowest.
- tag_names(pattern=None)[source]¶
Return the names of the tags, optionally only those matching pattern.
- tag_raise(tagname, abovethis=None)[source]¶
Raise the tag’s priority above the tag abovethis, or to the highest.
- validate(index)[source]¶
Explicitly validates the specified index based on the current callback set for the validatecommand option. Return 0 or 1 based on whether the cell was validated.
- width(column=None, **kwargs)[source]¶
If column and kwargs are not given, a dict describing all columns for which a width has been set is returned. If column is given, the width of that column is returned. If kwargs is given, then it sets the key/value pairs, where key is a column and value represents the width for the column.
- window_configure(index, option=None, **kwargs)[source]¶
Query or modify options associated with the embedded window given by index. This should also be used to add a new embedded window into the table.
If no option is specified, a dict describing all of the available options for index is returned. If option is specified, then the command returns a list describing the one named option. Lastly, if kwargs is given then it corresponds to option-value pairs that should be modified.
- window_delete(*indexes)[source]¶
Remove the embedded windows at the given indexes.
- Parameters:
indexes (str)
- Return type:
None
- window_names(pattern=None)[source]¶
Return the indexes of the embedded windows, optionally only those matching pattern.
- xview(index=None)[source]¶
If index is not given a tuple containing two fractions is returned, each fraction is between 0 and 1. Together they describe the horizontal span that is visible in the window.
If index is given the view in the window is adjusted so that the column given by index is displayed at the left edge of the window.
- xview_moveto(fraction)[source]¶
Adjusts the view in the window so that fraction of the total width of the table text is off-screen to the left. The fraction parameter must be a fraction between 0 and 1.
- Parameters:
fraction (float)
- Return type:
None
- xview_scroll(*L)[source]¶
Shift the view in the window left or right according to number and what. The ‘number’ parameter must be an integer. The ‘what’ parameter must be either units or pages or an abbreviation of one of these.
If ‘what’ is units, the view adjusts left or right by number cells on the display; if it is pages then the view adjusts by number screenfuls. If ‘number’ is negative then cells farther to the left become visible; if it is positive then cells farther to the right become visible.
- Parameters:
L (Any)
- Return type:
None
- yview(index=None)[source]¶
If index is not given a tuple containing two fractions is returned, each fraction is between 0 and 1. The first element gives the position of the table element at the top of the window, relative to the table as a whole. The second element gives the position of the table element just after the last one in the window, relative to the table as a whole.
If index is given the view in the window is adjusted so that the row given by index is displayed at the top of the window.
- yview_moveto(fraction)[source]¶
Adjusts the view in the window so that the element given by fraction appears at the top of the window. The fraction parameter must be a fraction between 0 and 1.
- Parameters:
fraction (float)
- Return type:
None
- yview_scroll(*L)[source]¶
Adjust the view in the window up or down according to number and what. The ‘number’ parameter must be an integer. The ‘what’ parameter must be either units or pages or an abbreviation of one of these.
If ‘what’ is units, the view adjusts up or down by number cells; if it is pages then the view adjusts by number screenfuls. If ‘number’ is negative then earlier elements become visible; if it is positive then later elements become visible.
- Parameters:
L (Any)
- Return type:
None
- tktable.table.TableCallback¶
The type of a Table callback, e.g. for browsecommand or validatecommand.
alias of
Callable[[TableEvent],Any]