Web Analytics Made Easy - Statcounter
Skip to content

Table

Table documentation

Table(
    values,
    headings = None,
    visible_column_map = None,
    col_widths = None,
    cols_justification = None,
    def_col_width = 10,
    auto_size_columns = True,
    max_col_width = 20,
    select_mode = None,
    display_row_numbers = False,
    starting_row_number = 0,
    num_rows = None,
    row_height = None,
    font = None,
    justification = "right",
    text_color = None,
    background_color = None,
    alternating_row_color = None,
    selected_row_colors = (None, None),
    header_text_color = None,
    header_background_color = None,
    header_font = None,
    header_border_width = None,
    header_relief = None,
    enable_cell_editing = False,
    cell_edit_colors = (None, None),
    cell_edit_select_colors = (None, None),
    row_colors = None,
    vertical_scroll_only = True,
    hide_vertical_scroll = False,
    border_width = None,
    sbar_trough_color = None,
    sbar_background_color = None,
    sbar_arrow_color = None,
    sbar_width = None,
    sbar_arrow_width = None,
    sbar_frame_color = None,
    sbar_relief = None,
    size = (None, None),
    s = (None, None),
    change_submits = False,
    enable_events = False,
    enable_click_events = False,
    right_click_selects = False,
    bind_return_key = False,
    pad = None,
    p = None,
    key = None,
    k = None,
    tooltip = None,
    right_click_menu = None,
    expand_x = False,
    expand_y = False,
    visible = True,
    metadata = None
)

Parameter Descriptions

Name Type Default Description
alternating_row_color str None if set then every other row will have this color in the background.
auto_size_columns bool True if True columns will be sized automatically
background_color str None color of background
bind_return_key bool False if True, pressing return key will cause event coming from Table, ALSO a left button double click will generate an event if this parameter is True
border_width int None Border width/depth in pixels
cell_edit_colors (str or (str, str)) (None, None) Sets the colors to use when editing a cell. Can be color string "foreground on background" or tuple (foreground, background). Defaults to swapping of table text and background colors
cell_edit_select_colors (str or (str, str)) (None, None) Sets the select colors to use when editing a cell. Can be color string "foreground on background" or tuple (foreground, background). Uses system default if none are set
change_submits bool False DO NOT USE. Only listed for backwards compat - Use enable_events instead
col_widths List[int] None Number of characters that each column will occupy
cols_justification List[str] or Tuple[str] or None None Justification for EACH column. Is a list of strings with the value 'l', 'r', 'c' that indicates how the column will be justified. Either no columns should be set, or have to have one for every colun
def_col_width int 10 Default column width in characters
display_row_numbers bool False if True, the first column of the table will be the row #
enable_cell_editing bool False If true, then if the cell is double-clicked, the value can be edited
enable_click_events bool False Turns on the element click events that will give you (row, col) click data when the table is clicked
enable_events bool False Turns on the element specific events. Table events happen when row is clicked
expand_x bool False If True the element will automatically expand in the X direction to fill available space
expand_y bool False If True the element will automatically expand in the Y direction to fill available space
font (str or (str, int[, str]) or None) None specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike
header_background_color str None sets the background color for the header
header_border_width (int or None) None Border width for the header portion
header_font (str or (str, int[, str]) or None) None specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike
header_relief (str or None) None Relief style for the header. Values are same as other elements that use relief. RELIEF_RAISED RELIEF_SUNKEN RELIEF_FLAT RELIEF_RIDGE RELIEF_GROOVE RELIEF_SOLID
header_text_color str None sets the text color for the header
headings List[str] None The headings to show on the top line
hide_vertical_scroll bool False if True vertical scrollbar will be hidden
justification str right 'left', 'right', 'center' are valid choices
k str or int or tuple or object None Same as the Key. You can use either k or key. Which ever is set will be used.
key str or int or tuple or object None Used with window.find_element and with return values to uniquely identify this element to uniquely identify this element
max_col_width int 20 Maximum width for all columns in characters
metadata Any None User metadata that can be set to ANYTHING
num_rows int None The number of rows of the table to display at a time
p (int, int or (int, int),(int,int) or int,(int,int)) or ((int, int),int) or int None Same as pad parameter. It's an alias. If EITHER of them are set, then the one that's set will be used. If BOTH are set, pad will be used
pad (int, int or (int, int),(int,int) or int,(int,int)) or ((int, int),int) or int None Amount of padding to put around element in pixels (left/right, top/bottom) or ((left, right), (top, bottom)) or an int. If an int, then it's converted into a tuple (int, int)
right_click_menu List[List[ List[str] or str ]] None A list of lists of Menu items to show when this element is right clicked. See user docs for exact format.
right_click_selects bool False If True, then right clicking a row will select that row if multiple rows are not currently selected
row_colors List[Tuple[int, str] or Tuple[Int, str, str]] None list of tuples of (row, background color) OR (row, foreground color, background color). Sets the colors of listed rows to the color(s) provided (note the optional foreground color)
row_height int None height of a single row in pixels
sbar_arrow_color str None Scrollbar color of the arrow at the ends of the scrollbar (it looks like a button). Switches to background color when mouse is over
sbar_arrow_width int None Scrollbar width of the arrow on the scrollbar. It will potentially impact the overall width of the scrollbar
sbar_background_color str None Scrollbar color of the background of the arrow buttons at the ends AND the color of the "thumb" (the thing you grab and slide). Switches to arrow color when mouse is over
sbar_frame_color str None Scrollbar Color of frame around scrollbar (available only on some ttk themes)
sbar_relief str None Scrollbar relief that will be used for the "thumb" of the scrollbar (the thing you grab that slides). Should be a constant that is defined at starting with "RELIEF_" - RELIEF_RAISED, RELIEF_SUNKEN, RELIEF_FLAT, RELIEF_RIDGE, RELIEF_GROOVE, RELIEF_SOLID
sbar_trough_color str None Scrollbar color of the trough
sbar_width int None Scrollbar width in pixels
select_mode str None Select Mode. Valid values start with "TABLE_SELECT_MODE_". Valid values are: TABLE_SELECT_MODE_NONE TABLE_SELECT_MODE_BROWSE TABLE_SELECT_MODE_EXTENDED
selected_row_colors str or (str, str) (None, None) Sets the text color and background color for a selected row. Same format as button colors - tuple ('red', 'yellow') or string 'red on yellow'. Defaults to theme's button color
size (int, int) (None, None) DO NOT USE! Use num_rows instead
starting_row_number int 0 The row number to use for the first row. All following rows will be based on this starting value. Default is 0.
text_color str None color of the text
tooltip str None text, that will appear when mouse hovers over the element
values List[List[str or int or float]] Your table data represented as a 2-dimensions table... a list of rows, with each row representing a row in your table.
vertical_scroll_only bool True if True only the vertical scrollbar will be visible
visible bool True set visibility state of the element
visible_column_map List[bool] None One entry for each column. False indicates the column is not shown

Class Properties

key
metadata
values
visible
widget

key

Returns key for the element. This is a READONLY property. Keys can be any hashable object (basically anything except a list... tuples are ok, but not lists)

key
Parameter Descriptions

Name Type Default Description
RETURN Any The window's Key

metadata

Metadata is an Element property that you can use at any time to hold any value

metadata
Parameter Descriptions

Name Type Default Description
RETURN Any the current metadata value

values

Returns the table values as a list of lists

values
Parameter Descriptions

Name Type Default Description
RETURN List[List[Any]] List of lists of table items

visible

Returns visibility state for the element. This is a READONLY property

visible
Parameter Descriptions

Name Type Default Description
RETURN bool Visibility state for element

widget

Returns tkinter widget for the element. This is a READONLY property. The implementation is that the Widget member variable is returned. This is a backward compatible addition

widget
Parameter Descriptions

Name Type Default Description
RETURN (tkinter.Widget) The element's underlying tkinter widget

Class Methods

 def bind
 def block_focus
 def expand
 def get
 def get_last_clicked_position
 def get_next_focus
 def get_previous_focus
 def get_size
 def grab_anywhere_exclude
 def grab_anywhere_include
 def hide_row
 def remove_tooltip
 def save_element_screenshot_to_disk
 def set_cursor
 def set_focus
 def set_hscroll_position
 def set_right_click_menu
 def set_size
 def set_tooltip
 def set_vscroll_position
 def unbind
 def unhide_row
 def update

bind

Used to add tkinter events to an Element. The tkinter specific data is in the Element's member variable user_bind_event

bind(
    bind_string,
    key_modifier,
    propagate = True
)

Parameter Descriptions

Name Type Default Description
bind_string str The string tkinter expected in its bind function
key_modifier str Additional data to be added to the element's key when event is returned
propagate bool True If True then tkinter will be told to propagate the event to the element

block_focus

Enable or disable the element from getting focus by using the keyboard. If the block parameter is True, then this element will not be given focus by using the keyboard to go from one element to another. You CAN click on the element and utilize it.

block_focus(
    block = True
)

Parameter Descriptions

Name Type Default Description
block bool True if True the element will not get focus via the keyboard

expand

Causes the Element to expand to fill available space in the X and Y directions. Can specify which or both directions

expand(
    expand_x = False,
    expand_y = False,
    expand_row = True
)

Parameter Descriptions

Name Type Default Description
expand_row bool True If True the row containing the element will also expand. Without this your element is "trapped" within the row
expand_x bool False If True Element will expand in the Horizontal directions
expand_y bool False If True Element will expand in the Vertical directions

get

Get the selected rows using tktiner's selection method. Returns a list of the selected rows.

get()

Parameter Descriptions

Name Type Default Description
RETURN List[int] a list of the index of the selected rows (a list of ints)

get_last_clicked_position

Returns a tuple with the row and column of the cell that was last clicked. Headers will have a row == -1 and the Row Number Column (if present) will have a column == -1

get_last_clicked_position()

Parameter Descriptions

Name Type Default Description
RETURN (int or None, int or None) The (row,col) position of the last cell clicked in the table

get_next_focus

Gets the next element that should get focus after this element.

get_next_focus()

Parameter Descriptions

Name Type Default Description
RETURN Element Element that will get focus after this one

get_previous_focus

Gets the element that should get focus previous to this element.

get_previous_focus()

Parameter Descriptions

Name Type Default Description
RETURN Element Element that should get the focus before this one

get_size

Return the size of an element in Pixels. Care must be taken as some elements use characters to specify their size but will return pixels when calling this get_size method.

get_size()

Parameter Descriptions

Name Type Default Description
RETURN (int, int) width and height of the element

grab_anywhere_exclude

Excludes this element from being used by the grab_anywhere feature Handy for elements like a Graph element when dragging is enabled. You want the Graph element to get the drag events instead of the window dragging.

grab_anywhere_exclude()

grab_anywhere_include

Includes this element in the grab_anywhere feature This will allow you to make a Multline element drag a window for example

grab_anywhere_include()

hide_row

Hide the entire row an Element is located on. Use this if you must have all space removed when you are hiding an element, including the row container

hide_row()

remove_tooltip

Removes a previiously created tooltip for an element

remove_tooltip()

save_element_screenshot_to_disk

Saves an image of the PySimpleGUI window provided into the filename provided

save_element_screenshot_to_disk(
    filename = None
)

Parameter Descriptions

Name Type Default Description
RETURN (PIL.ImageGrab or None) A PIL ImageGrab object that can be saved or manipulated

set_cursor

Sets the cursor for the current Element. "Cursor" is used in 2 different ways in this call. For the parameter "cursor" it's actually the mouse pointer. If you do not want any mouse pointer, then use the string "none" For the parameter "cursor_color" it's the color of the beam used when typing into an input element

set_cursor(
    cursor = None,
    cursor_color = None
)

Parameter Descriptions

Name Type Default Description
cursor str None The tkinter cursor name
cursor_color str None color to set the "cursor" to

set_focus

Sets the current focus to be on this element

set_focus(
    force = False
)

Parameter Descriptions

Name Type Default Description
force bool False if True will call focus_force otherwise calls focus_set

set_hscroll_position

Attempts to set the horizontal scroll postition for an element's Widget

set_hscroll_position(
    percent_from_left
)

Parameter Descriptions

Name Type Default Description
percent_from_left float From 0 to 1.0, the percentage from the left to move scrollbar to

set_right_click_menu

Sets a right click menu for an element. If a menu is already set for the element, it will call the tkinter destroy method to remove it

set_right_click_menu(
    menu = None
)

Parameter Descriptions

Name Type Default Description
menu List[List[ List[str] or str ]] None A list of lists of Menu items to show when this element is right clicked. See user docs for exact format.

set_size

Changes the size of an element to a specific size. It's possible to specify None for one of sizes so that only 1 of the element's dimensions are changed.

set_size(
    size = (None, None)
)

Parameter Descriptions

Name Type Default Description
size (int, int) (None, None) The size in characters, rows typically. In some cases they are pixels

set_tooltip

Called by application to change the tooltip text for an Element. Normally invoked using the Element Object such as: window.Element('key').SetToolTip('New tip').

set_tooltip(
    tooltip_text
)

Parameter Descriptions

Name Type Default Description
tooltip_text str or None the text to show in tooltip. If None then no tip will be shown

set_vscroll_position

Attempts to set the vertical scroll postition for an element's Widget

set_vscroll_position(
    percent_from_top
)

Parameter Descriptions

Name Type Default Description
percent_from_top float From 0 to 1.0, the percentage from the top to move scrollbar to

unbind

Removes a previously bound tkinter event from an Element.

unbind(
    bind_string
)

Parameter Descriptions

Name Type Default Description
bind_string str The string tkinter expected in its bind function

unhide_row

Unhides (makes visible again) the row container that the Element is located on. Note that it will re-appear at the bottom of the window / container, most likely.

unhide_row()

update

Changes some of the settings for the Table Element. Must call Window.Read or Window.Finalize prior

Changes will not be visible in your window until you call window.read or window.refresh.

If you change visibility, your element may MOVE. If you want it to remain stationary, use the "layout helper" function "pin" to ensure your element is "pinned" to that location in your layout so that it returns there when made visible.

update(
    values = None,
    num_rows = None,
    visible = None,
    select_rows = None,
    alternating_row_color = None,
    row_colors = None
)

Parameter Descriptions

Name Type Default Description
alternating_row_color str None the color to make every other row
num_rows int None How many rows to display at a time
row_colors List[Tuple[int, str] or Tuple[Int, str, str]] None list of tuples of (row, background color) OR (row, foreground color, background color). Changes the colors of listed rows to the color(s) provided (note the optional foreground color)
select_rows List[int] None List of rows to select as if user did
values List[List[str or int or float]] None A new 2-dimensional table to show
visible bool None if True then will be visible