tkonstructor 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tkonstructor-0.1.0/PKG-INFO +10 -0
- tkonstructor-0.1.0/README.txt +27 -0
- tkonstructor-0.1.0/pyproject.toml +20 -0
- tkonstructor-0.1.0/setup.cfg +4 -0
- tkonstructor-0.1.0/tkonstructor/__init__.py +1 -0
- tkonstructor-0.1.0/tkonstructor/card_area.py +78 -0
- tkonstructor-0.1.0/tkonstructor.egg-info/PKG-INFO +10 -0
- tkonstructor-0.1.0/tkonstructor.egg-info/SOURCES.txt +8 -0
- tkonstructor-0.1.0/tkonstructor.egg-info/dependency_links.txt +1 -0
- tkonstructor-0.1.0/tkonstructor.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tkonstructor
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A universal card designer for Tkinter with scrolling and grid support.
|
|
5
|
+
Author: FiRe
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.7
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
A library for creating evolving regions with cards in Tkinter.
|
|
2
|
+
|
|
3
|
+
1.First of all, create a card class, example:
|
|
4
|
+
|
|
5
|
+
class MaterialTemplate(Frame):
|
|
6
|
+
def __init__(self, parent, row):
|
|
7
|
+
super().__init__(parent, bd=1, relief=SOLID, pady=10)
|
|
8
|
+
|
|
9
|
+
Label(self, text=row[1]).grid(row=0, column=0)
|
|
10
|
+
Label(self, text=row[2]).grid(row=1, column=0)
|
|
11
|
+
Label(self, text=row[3]).grid(row=0, column=1)
|
|
12
|
+
Label(self, text=row[4]).grid(row=1, column=1)
|
|
13
|
+
self.columnconfigure(1, weight=1)
|
|
14
|
+
|
|
15
|
+
2.Create function for your card creation with variable (list or etc.)
|
|
16
|
+
|
|
17
|
+
def create_material_card(info_list):
|
|
18
|
+
card_area.render(info_list, MaterialTemplate)
|
|
19
|
+
|
|
20
|
+
3.Create a card area where cards will be created
|
|
21
|
+
|
|
22
|
+
card_area = TKonstructor.CardArea(main_window, columns=2, card_width=800, align="left")
|
|
23
|
+
card_area.pack(expand=True, fill=BOTH, side=RIGHT)
|
|
24
|
+
|
|
25
|
+
4.Now you can call your function and it will create a card in your Tkinter application
|
|
26
|
+
|
|
27
|
+
create_material_card(get_materials_list())
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tkonstructor"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="FiRe"},
|
|
10
|
+
]
|
|
11
|
+
description = "A universal card designer for Tkinter with scrolling and grid support."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.7"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .card_area import CardArea
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import tkinter as tk
|
|
2
|
+
from tkinter import ttk
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class CardArea(tk.Frame):
|
|
6
|
+
"""
|
|
7
|
+
Универсальный контейнер для карточек с поддержкой сетки.
|
|
8
|
+
:param card_width: Общая ширина контейнера (int).
|
|
9
|
+
:param align: Выравнивание контейнера ("center", "left", "right").
|
|
10
|
+
:param columns: Количество карточек в один ряд (int).
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, parent, card_width=None, align="center", columns=1, **kwargs):
|
|
14
|
+
super().__init__(parent, **kwargs)
|
|
15
|
+
|
|
16
|
+
self.card_width = card_width
|
|
17
|
+
self.align = align
|
|
18
|
+
self.columns = max(1, columns) # Защита от 0 или отрицательных чисел
|
|
19
|
+
|
|
20
|
+
self.canvas = tk.Canvas(self, highlightthickness=0)
|
|
21
|
+
self.scrollbar = ttk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
|
|
22
|
+
self.scrollable_frame = tk.Frame(self.canvas)
|
|
23
|
+
|
|
24
|
+
self.scrollable_frame.bind(
|
|
25
|
+
"<Configure>",
|
|
26
|
+
lambda e: self.canvas.configure(scrollregion=self.canvas.bbox("all"))
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
anchor_map = {"left": "nw", "center": "n", "right": "ne"}
|
|
30
|
+
self.anchor = anchor_map.get(self.align, "n")
|
|
31
|
+
|
|
32
|
+
self.canvas_window = self.canvas.create_window(
|
|
33
|
+
(0, 0),
|
|
34
|
+
window=self.scrollable_frame,
|
|
35
|
+
anchor=self.anchor
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
self.canvas.bind("<Configure>", self._on_canvas_configure)
|
|
39
|
+
self.canvas.configure(yscrollcommand=self.scrollbar.set)
|
|
40
|
+
self.canvas.pack(side="left", fill="both", expand=True)
|
|
41
|
+
self.scrollbar.pack(side="right", fill="y")
|
|
42
|
+
|
|
43
|
+
self.canvas.bind_all("<MouseWheel>", self._on_mousewheel)
|
|
44
|
+
|
|
45
|
+
def _on_canvas_configure(self, event):
|
|
46
|
+
if self.card_width:
|
|
47
|
+
self.canvas.itemconfig(self.canvas_window, width=self.card_width)
|
|
48
|
+
if self.align == "center":
|
|
49
|
+
self.canvas.coords(self.canvas_window, event.width / 2, 0)
|
|
50
|
+
elif self.align == "right":
|
|
51
|
+
self.canvas.coords(self.canvas_window, event.width, 0)
|
|
52
|
+
else:
|
|
53
|
+
self.canvas.coords(self.canvas_window, 0, 0)
|
|
54
|
+
else:
|
|
55
|
+
self.canvas.itemconfig(self.canvas_window, width=event.width)
|
|
56
|
+
self.canvas.coords(self.canvas_window, 0, 0)
|
|
57
|
+
|
|
58
|
+
def _on_mousewheel(self, event):
|
|
59
|
+
self.canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
|
|
60
|
+
|
|
61
|
+
def render(self, data_list, template_class):
|
|
62
|
+
"""Отрисовывает карточки в виде сетки."""
|
|
63
|
+
# Очистка
|
|
64
|
+
for child in self.scrollable_frame.winfo_children():
|
|
65
|
+
child.destroy()
|
|
66
|
+
|
|
67
|
+
# Настройка веса колонок, чтобы они были равными
|
|
68
|
+
for col in range(self.columns):
|
|
69
|
+
self.scrollable_frame.columnconfigure(col, weight=1)
|
|
70
|
+
|
|
71
|
+
# Размещение карточек
|
|
72
|
+
for index, item in enumerate(data_list):
|
|
73
|
+
row = index // self.columns # Целочисленное деление для номера строки
|
|
74
|
+
column = index % self.columns # Остаток от деления для номера колонки
|
|
75
|
+
|
|
76
|
+
card = template_class(self.scrollable_frame, item)
|
|
77
|
+
# Используем grid вместо pack
|
|
78
|
+
card.grid(row=row, column=column, padx=10, pady=5, sticky="nsew")
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tkonstructor
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A universal card designer for Tkinter with scrolling and grid support.
|
|
5
|
+
Author: FiRe
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.7
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tkonstructor
|