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.
Installation
TkClassWizard can be installed though command prompt/terminal using the bottom commands.
Pre-requirement: Python (minimum v3.8)
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
TkClassWiz-1.1.1.tar.gz
(22.7 kB
view details)
Built Distribution
File details
Details for the file TkClassWiz-1.1.1.tar.gz
.
File metadata
- Download URL: TkClassWiz-1.1.1.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae43e794b7989db4c5f385fdd1b5b7fddd9d53eab63b11c2dec65ce5a48e4971 |
|
MD5 | 4a66fbfb5aa62ad4e9cca722dab862ab |
|
BLAKE2b-256 | 1ba1400ba0ab0002a5c455d7392ad7c3c15063175da24152f0efd8b979f2fc46 |
File details
Details for the file TkClassWiz-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: TkClassWiz-1.1.1-py3-none-any.whl
- Upload date:
- Size: 29.9 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 | cc1ef6f2189500aecb4aab8deb835d2d6f652c2983ac21c007ce04e3b820b160 |
|
MD5 | 92e1ab86a1b06c69b78b30e3b8ebe92a |
|
BLAKE2b-256 | 3d1dd04639ac02bb1c4ada63b9bff55ba3afc1bc3cb69fa3c2589e0a85be84fe |