Skip to main content

Python Tkinter Table complement

Project description

tktabl

This proyect intends to be a complement on managing tables within the Python Tkinter GUI.

Installation

Run the following to install:

$ pip install tktabl

Usage

Import

As tktable is a complement to tkinter, you must import it in your code:

import tkinter as tk
import tktabl

Create a table

Creating a table requires a tkinter root as an argument. This will create a default 5x4 table in its own tkinter frame. Note that the first row is a column headers row.

root = tk.Tk()
table = tktable.Table(root)
table.pack()

You can specify it size passing 2 additional arguments (col, row), e.g.:

root = tk.Tk()
table = tktable.Table(root, col=3, row=5)
table.pack()

This will create a 6x3 table where the first row is a column headers row.

You can pass a list of strings as column headers, e.g.:

headers = ["ID", "Name", "Age"]

root = tk.Tk()
table = tktable.Table(root, headers=headers)
table.pack()

This will create a 5x3 table where the first row is the column headers row with the values "ID", "Name", and "Age" respectively

You can pass a list of dictionaries with the data you want to display, e.g.:

data = [
    {"ID": 1, "Name": "Juan", "Age": 24},
    {"ID": 2, "Address": "5th 20-22"}
]

root = tk.Tk()
table = tktable.Table(root, data=data)
table.pack()

Note that not every dictionary has the same keys. This, will create a 4x3 table. First row will be a row with headers "ID", "Name", "Age" and "Address". Second row will be the data of the first dictionary. Third row will be the data of the second dictionary. (If the dictionary doesn't has any value in a given header, the corresponding cell will be left blank)

Finally, you can mix all these arguments, e.g.:

...
table = tktable.Table(root, row=5, headers=headers, data=data)
table.pack()

In this case, it will create a table where there will be as many columns as headers in the headers variable plus the data variable without repeating themselves

After creating the table and before running your app, you must pack it with the Table.pack() function.

Usefull methods

  • Table.get_cell(row, column): will return a Cell object in the corresponding row and column.

  • Table.get_data(): will return a list of dictionaries, as many as rows are in the table, ignoring headers row, and each dictionary will have as many named keys as columns are in the table.

  • Table.get_row_data(row): will return a dictionary with as many keys as columns are in the table and with values corresponding the number of row passed as argument (Row 0 is the first row after the header row)

  • Cell.get_value(): will return the value displayed by the cell

  • Cell.set_value(value): Cell will display the value passed as argument

Some features

Simple left click on a cell will highlight it. Double left click will highlight its row. Triple left click will highlight its column.

Work in progress...

Changelog

v 0.2.0[02/28/2021]: The table includes its own tkinter frame master. Added set and get data functions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tktabl-0.2.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tktabl-0.2.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file tktabl-0.2.0.tar.gz.

File metadata

  • Download URL: tktabl-0.2.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.1 Windows/10

File hashes

Hashes for tktabl-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c5fe4f128401d861c11e4c1950c7a417442617800dcbac881df82bad552c716f
MD5 500975548bf9b81259bf443c33ee1706
BLAKE2b-256 aad54ac1fa2eb20e2eef0b70c9cda6404188ffdc6fae9a84cba6ddcc4d097025

See more details on using hashes here.

File details

Details for the file tktabl-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tktabl-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.1 Windows/10

File hashes

Hashes for tktabl-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 01e0b413c33465985c0d9a128ce0a59f42d43b598629011ea9e7df512120a720
MD5 a85dad540571e6503798725ce60b37bf
BLAKE2b-256 637c189806c895891cc32273017d3ca32751b5f6d7ac5a32d2935fd14e2e5835

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page