Skip to main content

tkdata

Create Tkinter forms easily. This library allows you to create a Tkinter GUI easily from a dict containing the structure of the window. This library lets you only create a limited set of widgets, namely:

  1. An entry to get a string.
  2. An entry to get an integer.
  3. An entry to get a float.
  4. A checkbox to get a boolean.
  5. A combobox to get a string from a set of choices.
  6. A widget to select a file (and get a string of its path).
  7. A widget to select a folder (and get a string of its path).

You can group these widgets, and even group multiple groups of widgets. You can specify the position of these groups in a grid inside the window too.

Installation

pip install tkdata

How to use it

Here is an example on how to use it:

from tkdata import TkData

# Schema of the program
schema = {
    "str_field": {
        "type": "str",
        "default": "Default value for str_field",
        "help": "Explanation about what string_field variable means",
        "label": "String Field"
    },
    "int_field": {
        "type": "int",
        "default": 1,
        "help": "Explanation about what int_field variable means",
        "label": "Integer Field"
    },
    "float_field": {
        "type": "float",
        "default": 1.0,
        "help": "Explanation about what float_field variable means",
        "label": "Float Field"
    },
    "bool_field": {
        "type": "bool",
        "default": True,
        "help": "Explanation about what bool_field variable means",
        "label": "Boolean Field"
    },
    "choice_field": {
        "type": "choice",
        "values": ["option 1", "option 2", "option 3"],
        "default": "option 1",
        "help": "Explanation about what choice_field variable means",
        "label": "Choice Field"
    },
    "file_field": {
        "type": "file",
        "default": "/path/to/file.extension",
        "help": "Explanation about what file_field variable means",
        "label": "File Field"
    },
    "folder_field": {
        "type": "folder",
        "default": "/path/to/folder/",
        "help": "Explanation about what folder_field variable means",
        "label": "Folder Field"
    },
    "button": {
        "type": "button",
        "text": "text inside the button"
    }
}

# Create TkData instance with the schema dict. If This can not be done after TkData
# intantiation, you can use gui.init(schema) function after it.
gui = TkData(schema)

# Get the data from the tkdata interface
args = gui.d

# Assign a function to a button named "button" specified in the schema.
# In this example, when the button is clicked all the data dict is printed 
gui.s['button'].bind('<Button-1>', lambda e: print(args))

# Start the loop of tkinter
gui.mainloop()

This code will show a Tkinter GUI with widgets to modify each element specified in the schema (except the button widget).

In the following example we show how to group widgets and set the location of each group.

import tkinter as tk

from tkdata import TkData

schema = {
    "group_1": {"type": "group", "pos": {"row": 0, "column": 0, "columnspan": 2}, "children": {
        "group_1.1": {"type": "frame", "pos": {"row": 0, "column": 0}, "children": {
            "str_field_with_label": { "type": "str", "label": "String Field" },
            "str_field_no_label": { "type": "str" }
        }},
        "group_1.2": {"type": "frame", "pos": {"row": 0, "column": 1}, "children": {
            "int_field": { "type": "int" },
            "float_field": { "type": "float" }
        }}
    }},
    "group_2": {"type": "frame", "pos": {"row": 1, "column": 0}, "children": {
        "bool_field": { "type": "bool" },
        "choice_field": { 
            "type": "choice",
            "values": ["option 1", "option 2", "option 3"]
        }
    }},
    "group_3": {"type": "frame", "pos": {"row": 1, "column": 1}, "children": {
        "file_field": { "type": "file" },
        "folder_field": { "type": "folder" },
        "button": { "type": "button", "text": "Print dict" }
    }}
}

gui = TkData(schema)

def show_message(event):
    window = tk.Toplevel(master=gui)
    message = tk.Message(master=window, text=str(gui.d))
    message.pack(fill='x', padx=10, pady=10)

gui.s['group_3']['button'].bind('<Button-1>', show_message)
gui.mainloop()

In this example group_2 and group_3 are of type frame, a type to group widgets; and group_1 is of type group, a type to group multiple frames. To position frames and groups you have to use same options for placing widgets inside a grid on Tkinter, and place these options in a dict inside the schema of the frame or group with the attribute pos. This is shown in the last example.

To do

  1. Add more widgets.
  2. Add a way to make validation on the fields.

Release files for tkdata 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tkdata 0.0.4
File Size Uploaded
tkdata-0.0.4.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tkdata 0.0.4
File Interpreter ABI Platform
tkdata-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / tkdata-0.0.4.tar.gz

Download URL tkdata-0.0.4.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9fcef736d1bb5ebfd13e75c9c46060601a02e11cf154d52039a476ff5b9c2ab2
BLAKE2b-256 checksum
How to use checksums
a098d06c83cfa899c70460591c3c0331eece88d59df406f8d1491c675b516a31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.5

Release files / tkdata-0.0.4-py3-none-any.whl

Download URL tkdata-0.0.4-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08a4a6f294c1450a273a6a4637a18274fd0aa2bf4a1ab74c53f467d57ec49b04
BLAKE2b-256 checksum
How to use checksums
0db8536fc7fc6594c7c47d1d316ecac2fa50e61d52a6da6c2b072d375008b78a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page