[~] FIX width
This commit is contained in:
parent
d0df8cce2d
commit
cf62a0e750
@ -2,12 +2,15 @@ import customtkinter as ctk
|
||||
|
||||
def darken_color_rgb(hex_color, amount=30):
|
||||
"""Затемняет цвет, вычитая значение из каждого компонента RGB"""
|
||||
hex_color = hex_color.lstrip("#")
|
||||
r, g, b = tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
|
||||
|
||||
# Уменьшаем компоненты, не давая им уйти в минус
|
||||
r, g, b = max(0, r - amount), max(0, g - amount), max(0, b - amount)
|
||||
try:
|
||||
hex_color = hex_color.lstrip("#")
|
||||
r, g, b = tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
|
||||
|
||||
# Уменьшаем компоненты, не давая им уйти в минус
|
||||
r, g, b = max(0, r - amount), max(0, g - amount), max(0, b - amount)
|
||||
except Exception as e:
|
||||
print(e, hex_color)
|
||||
raise e
|
||||
return f"#{r:02X}{g:02X}{b:02X}"
|
||||
|
||||
class CTkTableFrame(ctk.CTkFrame):
|
||||
@ -44,6 +47,7 @@ class CTkTableFrame(ctk.CTkFrame):
|
||||
def _prepare_columns(self):
|
||||
# Применяем шаблон значений по умолчанию
|
||||
default_column = {"width": 0, "align": "left", "name": "N/A"}
|
||||
self._columns.clear()
|
||||
for col in self.columns:
|
||||
if type(col) == dict:
|
||||
if "width" not in col:
|
||||
@ -65,16 +69,22 @@ class CTkTableFrame(ctk.CTkFrame):
|
||||
|
||||
def _build_header(self):
|
||||
"""Создает заголовок таблицы."""
|
||||
header_frame = ctk.CTkFrame(self, fg_color="gray30", corner_radius=10)
|
||||
header_frame.pack(fill="x", padx=0, pady=1)
|
||||
self.header_frame = ctk.CTkFrame(self, fg_color="gray30", corner_radius=10)
|
||||
self.header_frame.pack(fill="x", padx=0, pady=1)
|
||||
|
||||
# Заголовки
|
||||
for col in self._columns:
|
||||
header_label = ctk.CTkLabel(
|
||||
header_frame, text=col["name"], width=col["width"], anchor=col["align"], padx=5
|
||||
self.header_frame, text=col["name"], width=col["width"], anchor=col["align"], padx=5
|
||||
)
|
||||
header_label.pack(side="left", padx=4, pady=3)
|
||||
|
||||
def _update_header(self):
|
||||
"""Обновляет заголовок таблицы."""
|
||||
for i, col in enumerate(self._columns):
|
||||
header_label = self.header_frame.winfo_children()[i]
|
||||
header_label.configure(width=col["width"], anchor=col["align"])
|
||||
|
||||
@staticmethod
|
||||
def __row_enter(frame, e, color="gray40"):
|
||||
frame.configure(fg_color=color)
|
||||
@ -111,6 +121,8 @@ class CTkTableFrame(ctk.CTkFrame):
|
||||
|
||||
def create_table(self):
|
||||
"""Создает таблицу с заголовками и данными, используя параметры из словаря."""
|
||||
self._prepare_columns()
|
||||
self._update_header()
|
||||
self._rows = [None] * len(self._data)
|
||||
self._rows_settings = [None] * len(self._data)
|
||||
loading = self.loading_frame.winfo_children()[0]
|
||||
|
Loading…
x
Reference in New Issue
Block a user