Skip to content

Table

A Table widget displays tabular data organized into rows and columns with fixed headers. It supports custom column sizes, individual column text alignments, multi-row selection, and automatic column sorting when headers are clicked.

Examples

Coming soon!


Creating a Table widget

my_table = gp.Table(headings)

Parameters

  • headings (list of strings): A list of strings corresponding to the headings of the table columns.

Properties

Name Type Description
.data list of lists Gets or sets all data in the table as a list of lists (or tuples). Each inner list must match the number of columns.
.selected list/tuple, or list of lists if multiple_selection is enabled Returns the selected data row(s) in the table. Returns None if no row is selected.
.selected_row integer, or list of integers if multiple_selection is enabled Gets or sets the index (or indices), starting from 0, of the selected row(s).
.multiple_selection boolean Gets or sets whether multiple row selection is enabled for the table.
.height integer Gets or sets the height of the table as the number of visible lines.
.disabled boolean Gets or sets whether the table widget is disabled.
.sortable boolean Gets or sets whether the data can be sorted by clicking on the column headings.

Methods

Name Returns Description
.add_row(data) None Adds a row of data to the end of the table. data must be a list or tuple with the same number of items as the table has columns.
.add_row_to_top(data) None Adds a row of data to the top of the table. data must be a list or tuple with the same number of items as the table has columns.
.add_row_at(index, data) None Adds a row of data to the table at a specified index. data must be a list or tuple with the same number of items as the table has columns.
.remove_row(index) list Removes and returns the row of data at the specified index from the table.
.remove_selected() list, or list of lists if multiple_selection is enabled Removes and returns the currently selected row(s) from the table.
.clear() None Removes all data rows from the table.
.select_row(index) None Selects the row at the specified index.
.select_all() None Selects all rows in the table if multiple_selection is enabled.
.select_none() None Clears any selected rows in the table.
.set_column_width(column, width) None Sets the width in pixels of the specified column index (starting from 0).
.set_column_widths(*widths) None Sets the widths in pixels for all columns of the table in order.
.set_column_alignment(column, align) None Sets the alignment of content in the specified column index. Must be "left", "center", or "right".
.set_column_alignments(*aligns) None Sets the alignment of all columns in order. Values must be "left", "center", or "right".

Events

This widget has no unique events. It supports the standard events listed below.

Standard events

  • .on_click
  • .on_double_click
  • .on_right_click
  • .on_middle_click
  • .on_mouse_down
  • .on_mouse_up
  • .on_mouse_enter
  • .on_mouse_leave
  • .on_key_press
  • .on_focus_gained
  • .on_focus_lost

Styles

Styles for this widget

How to specify colors

  • Colors can be specified as either a hex code (e.g. "#FF0000"), a CSS color name, or "transparent".
  • When specifying a color for a style, you can provide either a single color or two colors separated by a comma. If you provide two colors, the first will be used for light mode and the second for dark mode. For example, my_widget.text_color = "steelblue", "skyblue" would specify steelblue for light mode and sky blue for dark mode.
Name Description Default
.style.table_bg_color The background color of the table area.
.style.border_color The color of the border around the table.
.style.font_name The font family of the text inside the table cells.
.style.font_size The font size of the text inside the table cells.
.style.font_style The font style of the text inside the table cells ("normal" or "italic").
.style.font_weight The font weight of the text inside the table cells ("normal" or "bold").
.style.text_color The text color of the data cells.
.style.selected_color The background color of the selected row(s).
.style.header_bg_color The background color of the table header row.
.style.header_text_color The text color of the column headings. "white"
.style.header_font_name The font family of the column headings.
.style.header_font_size The font size of the column headings.
.style.header_font_weight The font weight of the column headings.
.style.header_font_style The font style of the column headings.