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.
Links
Need help? Contact me in my Discord server.
DOCUMENTATION: https://tkclasswizard.readthedocs.io/
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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file TkClassWiz-1.4.8.tar.gz
.
File metadata
- Download URL: TkClassWiz-1.4.8.tar.gz
- Upload date:
- Size: 28.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | afa0b4f34686e900abc5d031c27666cf71efdb8a925910870bc39aaa78f517f3 |
|
MD5 | 4cb97ad96257ef6eb5d021e87ea66f43 |
|
BLAKE2b-256 | efba04a8fcf7ee9f0b19eb1afc61715340c6b7af101655369a1d38d57fdea6cb |
File details
Details for the file TkClassWiz-1.4.8-py3-none-any.whl
.
File metadata
- Download URL: TkClassWiz-1.4.8-py3-none-any.whl
- Upload date:
- Size: 38.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64e7d26fa54f32ce286d07a8a5fca312e5b1fe694940addeb779742b684d096c |
|
MD5 | 21c57f736214ad64a2a657f5fe6c3357 |
|
BLAKE2b-256 | c172362609c6549a3f3bf95e1a64cd6ea28e2c5127abfff1eeb3e1491ac56ae7 |