class table_view.TableView(Widget)

A TableView provides a tabular view of data having a fixed number of columns and a variable number of rows. There may be a header providing titles for the columns. There is provision for scrolling and for allowing the user to select rows.

An auxiliary class TableColumn is used to configure the formatting of the headers and data.

By default, all headers and data are displayed textually, but this can be changed by overriding methods of the TableView.


TableView(nrows = None, height = None, header_height = None, row_height = None, scrolling = True)

The TableView is initialized with a width and height determined as follows:

If scrolling is true, the table will display scrolling arrows.


A list of TableColumn instances describing the columns of the table.

Font in which to display the column headers.

Foreground colour of the column headers.

Background colour of the column headers, or None.

Space to leave between the header and the rows.

Space to leave either side of the contents of a column.

Abstract Methods

Should return the number of rows in the table. Must be implemented.

Should return a sequence of data items for row number n. The data items may be of any type, provided they can be formatted as specified by the corresponding TableColumn. Must be implemented.

Should return true if row number n is to be considered selected. The default implementation always returns false.

n, event)
Called when row number n is clicked. The default implementation does nothing.

Default Methods

draw_header_cell(surface, colnum, rect, coldesc)
Draws the header of column number colnum. The rect is the rectangle corresponding to the header area, and coldesc is the TableColumn instance describing the column. By default, the column's title is displayed using the header_font and the alignment specified by coldesc.

surface, colnum, data, rect, coldesc)
Draws a cell of the table. The colnum is the column number, data is the data item to be displayed, rect is the rectangle corresponding to the cell, and coldesc is the TableColumn instance describing the column. By default, the data is formatted as specified by coldesc and rendered using the widget's font.