Create tkinter forms easily
Project description
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:
- An entry to get a string.
- An entry to get an integer.
- An entry to get a float.
- A checkbox to get a boolean.
- A combobox to get a string from a set of choices.
- A widget to select a file (and get a string of its path).
- 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
- Add more widgets.
- Add a way to make validation on the fields.
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
Built Distribution
File details
Details for the file tkdata-0.0.4.tar.gz
.
File metadata
- Download URL: tkdata-0.0.4.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fcef736d1bb5ebfd13e75c9c46060601a02e11cf154d52039a476ff5b9c2ab2 |
|
MD5 | 97c9ceb8e73bbeb5c75a6d2029937749 |
|
BLAKE2b-256 | a098d06c83cfa899c70460591c3c0331eece88d59df406f8d1491c675b516a31 |
File details
Details for the file tkdata-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: tkdata-0.0.4-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08a4a6f294c1450a273a6a4637a18274fd0aa2bf4a1ab74c53f467d57ec49b04 |
|
MD5 | 2ee3ae7db9818c44d39adee953854e62 |
|
BLAKE2b-256 | 0db8536fc7fc6594c7c47d1d316ecac2fa50e61d52a6da6c2b072d375008b78a |