CTkTable

repository·main·Indexed 43 days ago

https://github.com/akascape/ctktable

A simple table widget for CustomTkinter that provides features for row and column manipulation, cell editing, and selection. It supports dynamic data updates via methods like .insert(), .add_row(), and .update_values(), and allows for cell configuration using ctkbutton parameters.

Tokens
960
Snippets
2
Records
7
Agent score
6%

What's inside CTkTable

  1. Quickstart: Create a basic CTkTable

    main

    To use CTkTable, initialize a customtkinter.CTk root window, define a 2D list for your values, and instantiate the CTkTable widget. You can then pack or grid the table into your layout.

    import customtkinter
    from CTkTable import *
    
    root = customtkinter.CTk()
    
    value = [[1,2,3,4,5],
             [1,2,3,4,5],
             [1,2,3,4,5],
             [1,2,3,4,5],
             [1,2,3,4,5]]
    
    table = CTkTable(master=root, row=5, column=5, values=value)
    table.pack(expand=True, fill="both", padx=20, pady=20)
    
    root.mainloop()
  2. Initialize CTkTable with arguments

    main

    When instantiating CTkTable, you can pass several arguments to configure its appearance and behavior. Note that cells behave like ctkbutton objects, so most ctkbutton parameters are accepted.

    ParameterDescription
    masterParent widget
    valuesThe default values for the table
    row(Optional) Set number of default rows
    column(Optional) Set number of default columns
    padxInternal padding in x
    padyInternal padding in y
    colorsSet two fg_colors for the table (list), e.g., colors=["yellow", "green"]
    color_phaseSet color phase based on rows or columns, e.g., color_phase="vertical"
    orientationChange the orientation of table, vertical or horizontal
    header_colorDefine the topmost row color
    corner_radiusDefine the corner roundness of the table
    hover_colorEnable hover effect on the cells
    wraplengthSet the width of cell text
    justifyAnchor the position of the cell text
    commandSpecify a command when a table cell is pressed. The callback receives [row, column, value]
    other button parametersAll other ctkbutton parameters can be passed
  3. Select and deselect rows and columns

    main

    Manage selection states for cells, rows, or columns:

    • .select(row, column): Select one cell.
    • .select_row(row): Select a row.
    • .get_selected_row(): Get the values of the selected row.
    • .deselect_row(row): Deselect a row.
    • .select_column(column): Select a column.
    • .get_selected_column(): Get the values of the selected column.
    • .deselect_column(column): Deselect a column.
  4. Modify table data and structure

    main

    Use the following methods to manipulate the table's content and dimensions:

    • .insert(row, column, value, *args): Change specific cell index data. *args accepts ctkbutton parameters.
    • .add_row(index, values): Add a new row at the specified index.
    • .add_column(index, values): Add a new column at the specified index.
    • .edit_row(row_num, *args): Edit one full row at once.
    • .edit_column(column_num, *args): Edit one full column at once.
    • .delete_row(index): Remove one row.
    • .delete_column(index): Remove one column.
    • .delete_rows(indices): Remove multiple rows.
    • .delete_columns(indices): Remove multiple columns.
    • .update_values(values): Update all values at once.
    • .delete(row, column, *args): Delete the data from a specific index.
  5. Retrieve table values

    main

    Use these methods to extract data from the table:

    • .get(): Get all values in the table.
    • .get(row, column): Get the value of a specific cell.
    • .get_row(row): Get all values of a specific row.
    • .get_column(column): Get all values of a specific column.