Skip to main content

TkGen

About

tkgen is a python package that automatically generate a Tkinter form window from a Pyskema schema. It provide a simple interface to initialize the window and collect the data inputed by user. The data is provided as python native objects that would be valid regarding the schema. It depends on tkinter and Pyskema.

Installation

Recommended: Use pip install tkgen.

Manual: Clone this project. Run pip install . in this folder.

Usage

The main entrypoint of this package is the function tkgen.make_form. Here is a minimal exemple of its usage:

from tkgen import make_form
from pyskema import Node, AtomType

schema = Node.of_record({
    "a": Node.of_atom(AtomType.INT),
})

win = make_form(schema, print)
win.mainloop()

The first parameter of make_toplevel (the model) is the schema that define the form. The second parameter (the callback) is a function to be called when the form is submitted. The callback is passed a single argument which is either None (if the user pressed cancel) or the data inputed. This dictionary mirror the structure of the model.

Extracting data

Once the form is filled, you want to access its data. This is done through the callback parameter of make_form. This callback is an arbitrary function you should provide that will receive the data in the form of a dictionary.

Here is a simple example of saving the data in an arbitrary json file:

import json
from tkgen import make_form
from pyskema import Node, AtomType

model = Node.of_record({
    "filename": Node.of_atom(AtomType.STR),
    "Plumbus": Node.of_record({
        "number of schleem": Node.of_atom(AtomType.STR),
        "length of dinglepop": Node.of_atom(AtomType.FLOAT),
        "color of fleeb": Node.of_atom(AtomType.OPTION, [
            "pink",
            "red",
            "octarine",
        ]),
    }),
})

def save_data(result):
    filename = result["filename"]
    data = result["Plumbus"]
    with open(filename, "w") as f:
        json.dump(f, data)

win = make_form(model, save_data)
win.mainloop()

Loading data

You may want to be able to load back some data from a previous instance of the form. This is possible thanks to the init_data optional parameter. For simplicity it is also possible through the optional data parameter of make_form.

If you were to use the previous example and save a file named plumbus.json, the following example would load data from the json file and produce a filled form identical to what it looked when you saved the file.

import json
from tkgen import make_form
from pyskema import Node, AtomType

model = Node.of_record({
    "filename": Node.of_atom(AtomType.STR),
    "Plumbus": Node.of_record({
        "number of schleem": Node.of_atom(AtomType.STR),
        "length of dinglepop": Node.of_atom(AtomType.FLOAT),
        "color of fleeb": Node.of_atom(AtomType.OPTION, [
            "pink",
            "red",
            "octarine",
        ]),
    }),
})

with open(filename, "r") as f:
    data = json.load(f)

saved_data = {
    "filename": filename,
    "Plumbus": data,
}

def save_data(result):
    filename = result["filename"]
    data = result["Plumbus"]
    with open(filename, "w") as f:
        json.dump(f, data)

win = make_form(model, save_data, init_data=saved_data)
win.mainloop()

Metadata

Release files for tkgen 0.2.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 tkgen 0.2.4
File Size Uploaded Provenance Actions
tkgen-0.2.4.tar.gz 17.0 kB Without provenance Details for tkgen-0.2.4.tar.gz

Built distribution (wheel)

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

Total release size: 34.7 kB

Release files / tkgen-0.2.4.tar.gz

Download URL tkgen-0.2.4.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
120323cb48673b0b80b7cf541dc91749f21bc972541607ab78cc46423816e78a
BLAKE2b-256 checksum
How to use checksums
f7bfbe0f01bf51a95845981f97bb5677b2e9704fe9e679352f5b6496c5f65454
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / tkgen-0.2.4-py3-none-any.whl

Download URL tkgen-0.2.4-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01c474a43f7421848bf6ac734068ccd79ec2f0b9f3ce6c7ea06e395e938446a0
BLAKE2b-256 checksum
How to use checksums
fde76e726f1ea12d88ff8234bc276c22ed02c8ce5bad45311cc5622c2d423d9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Security for tkgen 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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