Skip to main content

Library for graphically defining objects based on class annotations. Works with Tkinter / TTKBootstrap

Project description

TkClassWizard - define objects graphically based on class annotations. The library allows users to create abstract “ObjectInfo” objects based on the class’s parameters, which can later be converted to real Python objects and vice versa.

Main features

  • Interactive definition of Python objects based on annotations.

  • Tkinter based

  • JSON templates

  • Polymorphism

  • Generic classes

  • Type aliases

  • Data validation

  • Conversion of defined data to Python objects and vice-versa.

Installation

TkClassWizard can be installed though command prompt/terminal using the bottom commands.

Pre-requirement: Python (minimum v3.9)

pip install tkclasswiz

Example

docs/source/guide/images/new_define_frame_struct_new_str.png
import tkinter as tk
import tkinter.ttk as ttk
import tkclasswiz as wiz


# Normal Python classes with annotations (type hints)
class Wheel:
    def __init__(self, diameter: float):
        self.diameter = diameter

class Car:
    def __init__(self, name: str, speed: float, wheels: list[Wheel]):
        self.name = name
        self.speed = speed
        self.wheels = wheels

# Tkinter main window
root = tk.Tk("Test")

# Modified tkinter Combobox that will store actual objects instead of strings
combo = wiz.ComboBoxObjects(root)
combo.pack(fill=tk.X, padx=5)

def make_car(old = None):
    """
    Function for opening a window either in new definition mode (old = None) or
    edit mode (old != None)
    """
    assert old is None or isinstance(old, wiz.ObjectInfo)

    window = wiz.ObjectEditWindow()  # The object definition window / wizard
    window.open_object_edit_frame(Car, combo, old_data=old)  # Open the actual frame

def print_defined():
    data = combo.get()
    data = wiz.convert_to_objects(data)  # Convert any abstract ObjectInfo objects into actual Python objects
    print(f"Object: {data}; Type: {type(data)}",)  # Print the object and it's datatype


# Main GUI structure
ttk.Button(text="Define Car", command=make_car).pack()
ttk.Button(text="Edit Car", command=lambda: make_car(combo.get())).pack()
ttk.Button(text="Print defined", command=print_defined).pack()
root.mainloop()

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

TkClassWiz-1.4.3.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

TkClassWiz-1.4.3-py3-none-any.whl (37.8 kB view details)

Uploaded Python 3

File details

Details for the file TkClassWiz-1.4.3.tar.gz.

File metadata

  • Download URL: TkClassWiz-1.4.3.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for TkClassWiz-1.4.3.tar.gz
Algorithm Hash digest
SHA256 ff090d7d04663108b35aed5be38da88d22b00e0d521691af164d7b37d61656c6
MD5 c30ef833a28d5dc8f7f48ea7a35d0ecc
BLAKE2b-256 c5f50bacd6b5a0b9d7ad6c034df662461b70f3718bf96e49084dc1e04b2ec6f6

See more details on using hashes here.

File details

Details for the file TkClassWiz-1.4.3-py3-none-any.whl.

File metadata

  • Download URL: TkClassWiz-1.4.3-py3-none-any.whl
  • Upload date:
  • Size: 37.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for TkClassWiz-1.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f7d3d2c5f60a6de0bd679b296c9ad86d83de2bdb013ef2f247c6cdfd959fa308
MD5 4246a77312e9befdbfb72e33ab8154c3
BLAKE2b-256 dcf7991415e9b9a00c3aebc5483edbbcd782d23c3b4f86d8e828173e12585910

See more details on using hashes here.

Supported by

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