ctk-split-pane 0.1.0__py3-none-any.whl
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.
- ctk_split_pane/__init__.py +6 -0
- ctk_split_pane/py.typed +0 -0
- ctk_split_pane/split_pane.py +437 -0
- ctk_split_pane-0.1.0.dist-info/METADATA +184 -0
- ctk_split_pane-0.1.0.dist-info/RECORD +8 -0
- ctk_split_pane-0.1.0.dist-info/WHEEL +5 -0
- ctk_split_pane-0.1.0.dist-info/licenses/LICENSE +21 -0
- ctk_split_pane-0.1.0.dist-info/top_level.txt +1 -0
ctk_split_pane/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
"""A resizable split-pane widget for CustomTkinter.
|
|
2
|
+
|
|
3
|
+
The widget manages two panes and a draggable divider with three grip dots,
|
|
4
|
+
double-click reset, minimum sizes and dark/light appearance support.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import tkinter as tk
|
|
10
|
+
from typing import Callable, Literal, Union
|
|
11
|
+
|
|
12
|
+
import customtkinter as ctk
|
|
13
|
+
|
|
14
|
+
Color = Union[str, tuple[str, str]]
|
|
15
|
+
Orientation = Literal["horizontal", "vertical"]
|
|
16
|
+
Grip = Literal["dots", "line", "none"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class CTkSplitPane(ctk.CTkFrame):
|
|
20
|
+
"""Two resizable panes separated by a draggable divider.
|
|
21
|
+
|
|
22
|
+
The content of each pane must be created inside ``split.first`` or
|
|
23
|
+
``split.second``::
|
|
24
|
+
|
|
25
|
+
split = CTkSplitPane(parent, initial=280, min_second=280)
|
|
26
|
+
split.pack(fill="both", expand=True)
|
|
27
|
+
|
|
28
|
+
left = ctk.CTkFrame(split.first)
|
|
29
|
+
left.pack(fill="both", expand=True)
|
|
30
|
+
right = ctk.CTkFrame(split.second)
|
|
31
|
+
right.pack(fill="both", expand=True)
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
master: Parent widget.
|
|
35
|
+
orientation: ``"horizontal"`` (panes side by side) or ``"vertical"``.
|
|
36
|
+
initial: Initial size of the second pane. Defaults to ``default``.
|
|
37
|
+
default: Size restored by double-click/reset.
|
|
38
|
+
min_first: Minimum size of the first pane.
|
|
39
|
+
min_second: Minimum size of the second pane. The divider never goes
|
|
40
|
+
below this value.
|
|
41
|
+
divider_width: Thickness of the divider in pixels.
|
|
42
|
+
grip: ``"dots"``, ``"line"`` or ``"none"``.
|
|
43
|
+
divider_color: Divider color or ``(light, dark)`` tuple.
|
|
44
|
+
grip_color: Grip color or ``(light, dark)`` tuple.
|
|
45
|
+
hover_color: Divider color while the mouse is over it.
|
|
46
|
+
cursor: Divider cursor; defaults to the appropriate resize cursor.
|
|
47
|
+
on_resize: Called with the new second-pane size after a resize.
|
|
48
|
+
on_reset: Called after a reset.
|
|
49
|
+
first_pane_kwargs: Extra options for the first internal CTkFrame.
|
|
50
|
+
second_pane_kwargs: Extra options for the second internal CTkFrame.
|
|
51
|
+
**kwargs: Passed to ``customtkinter.CTkFrame``.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
master,
|
|
57
|
+
*,
|
|
58
|
+
orientation: Orientation = "horizontal",
|
|
59
|
+
initial: int | None = None,
|
|
60
|
+
default: int | None = None,
|
|
61
|
+
min_first: int = 120,
|
|
62
|
+
min_second: int = 120,
|
|
63
|
+
divider_width: int = 10,
|
|
64
|
+
grip: Grip = "dots",
|
|
65
|
+
divider_color: Color = ("#d9d9d9", "#3a3a3a"),
|
|
66
|
+
grip_color: Color = ("#8a8a8a", "#9a9a9a"),
|
|
67
|
+
hover_color: Color = ("#c8c8c8", "#4a4a4a"),
|
|
68
|
+
cursor: str | None = None,
|
|
69
|
+
on_resize: Callable[[int], None] | None = None,
|
|
70
|
+
on_reset: Callable[[], None] | None = None,
|
|
71
|
+
first_pane_kwargs: dict | None = None,
|
|
72
|
+
second_pane_kwargs: dict | None = None,
|
|
73
|
+
**kwargs,
|
|
74
|
+
) -> None:
|
|
75
|
+
self._orientation: Orientation = (
|
|
76
|
+
"vertical" if orientation == "vertical" else "horizontal"
|
|
77
|
+
)
|
|
78
|
+
self._divider_width = max(4, int(divider_width))
|
|
79
|
+
self._min_first = max(0, int(min_first))
|
|
80
|
+
self._min_second = max(0, int(min_second))
|
|
81
|
+
self._grip: Grip = grip if grip in ("dots", "line", "none") else "dots"
|
|
82
|
+
|
|
83
|
+
default_size = int(default if default is not None else (initial if initial is not None else 250))
|
|
84
|
+
self._default = max(self._min_second, default_size)
|
|
85
|
+
initial_size = int(initial) if initial is not None else self._default
|
|
86
|
+
self._size_second = max(self._min_second, initial_size)
|
|
87
|
+
|
|
88
|
+
self._divider_color = divider_color
|
|
89
|
+
self._grip_color = grip_color
|
|
90
|
+
self._hover_color = hover_color
|
|
91
|
+
self._cursor = cursor or (
|
|
92
|
+
"sb_h_double_arrow"
|
|
93
|
+
if self._orientation == "horizontal"
|
|
94
|
+
else "sb_v_double_arrow"
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
self._on_resize = on_resize
|
|
98
|
+
self._on_reset = on_reset
|
|
99
|
+
self._second_visible = True
|
|
100
|
+
self._hover = False
|
|
101
|
+
self._drag_start: int | None = None
|
|
102
|
+
self._drag_size: int | None = None
|
|
103
|
+
self._atualizando = False
|
|
104
|
+
|
|
105
|
+
super().__init__(master, **kwargs)
|
|
106
|
+
|
|
107
|
+
first_kwargs = {"corner_radius": 0, "fg_color": "transparent"}
|
|
108
|
+
if first_pane_kwargs:
|
|
109
|
+
first_kwargs.update(first_pane_kwargs)
|
|
110
|
+
second_kwargs = {"corner_radius": 0, "fg_color": "transparent"}
|
|
111
|
+
if second_pane_kwargs:
|
|
112
|
+
second_kwargs.update(second_pane_kwargs)
|
|
113
|
+
|
|
114
|
+
self.first = ctk.CTkFrame(self, **first_kwargs)
|
|
115
|
+
self.second = ctk.CTkFrame(self, **second_kwargs)
|
|
116
|
+
|
|
117
|
+
# The internal panes must not grow according to their content;
|
|
118
|
+
# the pane size is controlled by the split grid.
|
|
119
|
+
for pane in (self.first, self.second):
|
|
120
|
+
pane.grid_propagate(False)
|
|
121
|
+
pane.configure(width=1, height=1)
|
|
122
|
+
|
|
123
|
+
self._divider = tk.Canvas(
|
|
124
|
+
self,
|
|
125
|
+
width=self._divider_width if self._is_horizontal else 1,
|
|
126
|
+
height=1 if self._is_horizontal else self._divider_width,
|
|
127
|
+
bg=self._apply_appearance_mode(self._divider_color),
|
|
128
|
+
highlightthickness=0,
|
|
129
|
+
bd=0,
|
|
130
|
+
relief="flat",
|
|
131
|
+
cursor=self._cursor,
|
|
132
|
+
takefocus=True,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
self._montar_grid()
|
|
136
|
+
self._configurar_eventos()
|
|
137
|
+
self._aplicar_tamanho()
|
|
138
|
+
self._desenhar()
|
|
139
|
+
|
|
140
|
+
# ------------------------------------------------------------------
|
|
141
|
+
# Propriedades
|
|
142
|
+
# ------------------------------------------------------------------
|
|
143
|
+
@property
|
|
144
|
+
def _is_horizontal(self) -> bool:
|
|
145
|
+
return self._orientation == "horizontal"
|
|
146
|
+
|
|
147
|
+
@property
|
|
148
|
+
def pane_a(self):
|
|
149
|
+
"""Alias for the first internal pane."""
|
|
150
|
+
return self.first
|
|
151
|
+
|
|
152
|
+
@property
|
|
153
|
+
def pane_b(self):
|
|
154
|
+
"""Alias for the second internal pane."""
|
|
155
|
+
return self.second
|
|
156
|
+
|
|
157
|
+
@property
|
|
158
|
+
def is_second_visible(self) -> bool:
|
|
159
|
+
return self._second_visible
|
|
160
|
+
|
|
161
|
+
def get_second_size(self) -> int:
|
|
162
|
+
return self._size_second
|
|
163
|
+
|
|
164
|
+
def get_default_size(self) -> int:
|
|
165
|
+
return self._default
|
|
166
|
+
|
|
167
|
+
# ------------------------------------------------------------------
|
|
168
|
+
# Grid
|
|
169
|
+
# ------------------------------------------------------------------
|
|
170
|
+
def _montar_grid(self) -> None:
|
|
171
|
+
if self._is_horizontal:
|
|
172
|
+
self.grid_rowconfigure(0, weight=1)
|
|
173
|
+
self.grid_columnconfigure(0, weight=1)
|
|
174
|
+
self.grid_columnconfigure(
|
|
175
|
+
1, weight=0, minsize=self._divider_width
|
|
176
|
+
)
|
|
177
|
+
self.grid_columnconfigure(
|
|
178
|
+
2, weight=0, minsize=self._size_second
|
|
179
|
+
)
|
|
180
|
+
self.first.grid(row=0, column=0, sticky="nsew")
|
|
181
|
+
self._divider.grid(row=0, column=1, sticky="ns")
|
|
182
|
+
self.second.grid(row=0, column=2, sticky="nsew")
|
|
183
|
+
else:
|
|
184
|
+
self.grid_rowconfigure(0, weight=1)
|
|
185
|
+
self.grid_rowconfigure(
|
|
186
|
+
1, weight=0, minsize=self._divider_width
|
|
187
|
+
)
|
|
188
|
+
self.grid_rowconfigure(
|
|
189
|
+
2, weight=0, minsize=self._size_second
|
|
190
|
+
)
|
|
191
|
+
self.grid_columnconfigure(0, weight=1)
|
|
192
|
+
self.first.grid(row=0, column=0, sticky="nsew")
|
|
193
|
+
self._divider.grid(row=1, column=0, sticky="ew")
|
|
194
|
+
self.second.grid(row=2, column=0, sticky="nsew")
|
|
195
|
+
|
|
196
|
+
def _configurar_eventos(self) -> None:
|
|
197
|
+
self.bind("<Configure>", self._ao_redimensionar, add="+")
|
|
198
|
+
self._divider.bind("<Configure>", self._ao_configurar_divisor, add="+")
|
|
199
|
+
self._divider.bind("<ButtonPress-1>", self._iniciar_arraste)
|
|
200
|
+
self._divider.bind("<B1-Motion>", self._arrastar)
|
|
201
|
+
self._divider.bind("<ButtonRelease-1>", self._finalizar_arraste)
|
|
202
|
+
self._divider.bind("<Double-Button-1>", self._resetar_evento)
|
|
203
|
+
self._divider.bind("<Enter>", self._entrar)
|
|
204
|
+
self._divider.bind("<Leave>", self._sair)
|
|
205
|
+
self._divider.bind("<Left>", lambda _e: self._tecla(1))
|
|
206
|
+
self._divider.bind("<Right>", lambda _e: self._tecla(-1))
|
|
207
|
+
self._divider.bind("<Up>", lambda _e: self._tecla(1))
|
|
208
|
+
self._divider.bind("<Down>", lambda _e: self._tecla(-1))
|
|
209
|
+
self._divider.bind("<Home>", lambda _e: self.reset())
|
|
210
|
+
|
|
211
|
+
def _aplicar_tamanho(self) -> None:
|
|
212
|
+
self._atualizando = True
|
|
213
|
+
try:
|
|
214
|
+
if not self._second_visible:
|
|
215
|
+
if self._is_horizontal:
|
|
216
|
+
self.grid_columnconfigure(1, minsize=0)
|
|
217
|
+
self.grid_columnconfigure(2, minsize=0)
|
|
218
|
+
else:
|
|
219
|
+
self.grid_rowconfigure(1, minsize=0)
|
|
220
|
+
self.grid_rowconfigure(2, minsize=0)
|
|
221
|
+
return
|
|
222
|
+
|
|
223
|
+
if self._is_horizontal:
|
|
224
|
+
self.grid_columnconfigure(2, minsize=self._size_second)
|
|
225
|
+
else:
|
|
226
|
+
self.grid_rowconfigure(2, minsize=self._size_second)
|
|
227
|
+
finally:
|
|
228
|
+
self._atualizando = False
|
|
229
|
+
|
|
230
|
+
def _max_second(self) -> int:
|
|
231
|
+
total = self.winfo_width() if self._is_horizontal else self.winfo_height()
|
|
232
|
+
if total <= 1:
|
|
233
|
+
return max(self._min_second, self._default)
|
|
234
|
+
return max(
|
|
235
|
+
self._min_second,
|
|
236
|
+
total - self._divider_width - self._min_first,
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
def _set_size(self, size: int, notificar: bool = True) -> None:
|
|
240
|
+
novo = max(self._min_second, min(int(size), self._max_second()))
|
|
241
|
+
alterou = novo != self._size_second
|
|
242
|
+
self._size_second = novo
|
|
243
|
+
self._aplicar_tamanho()
|
|
244
|
+
if alterou and notificar and self._on_resize is not None:
|
|
245
|
+
self._on_resize(novo)
|
|
246
|
+
|
|
247
|
+
# ------------------------------------------------------------------
|
|
248
|
+
# API pública
|
|
249
|
+
# ------------------------------------------------------------------
|
|
250
|
+
def set_second_size(self, size: int) -> None:
|
|
251
|
+
self._set_size(size)
|
|
252
|
+
|
|
253
|
+
def reset(self) -> None:
|
|
254
|
+
self._set_size(self._default)
|
|
255
|
+
if self._on_reset is not None:
|
|
256
|
+
self._on_reset()
|
|
257
|
+
return "break"
|
|
258
|
+
|
|
259
|
+
def set_default_size(self, size: int) -> None:
|
|
260
|
+
self._default = max(self._min_second, int(size))
|
|
261
|
+
|
|
262
|
+
def set_min_second(self, size: int) -> None:
|
|
263
|
+
self._min_second = max(0, int(size))
|
|
264
|
+
if self._default < self._min_second:
|
|
265
|
+
self._default = self._min_second
|
|
266
|
+
self._set_size(max(self._size_second, self._min_second))
|
|
267
|
+
|
|
268
|
+
def set_min_first(self, size: int) -> None:
|
|
269
|
+
self._min_first = max(0, int(size))
|
|
270
|
+
self._set_size(self._size_second)
|
|
271
|
+
|
|
272
|
+
def hide_second(self) -> None:
|
|
273
|
+
if not self._second_visible:
|
|
274
|
+
return
|
|
275
|
+
self._second_visible = False
|
|
276
|
+
self.second.grid_remove()
|
|
277
|
+
self._divider.grid_remove()
|
|
278
|
+
self._atualizando = True
|
|
279
|
+
try:
|
|
280
|
+
if self._is_horizontal:
|
|
281
|
+
self.grid_columnconfigure(1, minsize=0)
|
|
282
|
+
self.grid_columnconfigure(2, minsize=0)
|
|
283
|
+
else:
|
|
284
|
+
self.grid_rowconfigure(1, minsize=0)
|
|
285
|
+
self.grid_rowconfigure(2, minsize=0)
|
|
286
|
+
finally:
|
|
287
|
+
self._atualizando = False
|
|
288
|
+
|
|
289
|
+
def show_second(self) -> None:
|
|
290
|
+
if self._second_visible:
|
|
291
|
+
return
|
|
292
|
+
self._second_visible = True
|
|
293
|
+
self._atualizando = True
|
|
294
|
+
try:
|
|
295
|
+
if self._is_horizontal:
|
|
296
|
+
self.grid_columnconfigure(1, minsize=self._divider_width)
|
|
297
|
+
self.grid_columnconfigure(2, minsize=self._size_second)
|
|
298
|
+
self._divider.grid(row=0, column=1, sticky="ns")
|
|
299
|
+
self.second.grid(row=0, column=2, sticky="nsew")
|
|
300
|
+
else:
|
|
301
|
+
self.grid_rowconfigure(1, minsize=self._divider_width)
|
|
302
|
+
self.grid_rowconfigure(2, minsize=self._size_second)
|
|
303
|
+
self._divider.grid(row=1, column=0, sticky="ew")
|
|
304
|
+
self.second.grid(row=2, column=0, sticky="nsew")
|
|
305
|
+
finally:
|
|
306
|
+
self._atualizando = False
|
|
307
|
+
self._desenhar()
|
|
308
|
+
|
|
309
|
+
def toggle_second(self) -> None:
|
|
310
|
+
if self._second_visible:
|
|
311
|
+
self.hide_second()
|
|
312
|
+
else:
|
|
313
|
+
self.show_second()
|
|
314
|
+
|
|
315
|
+
# ------------------------------------------------------------------
|
|
316
|
+
# Eventos
|
|
317
|
+
# ------------------------------------------------------------------
|
|
318
|
+
def _ao_redimensionar(self, event=None) -> None:
|
|
319
|
+
if self._atualizando or not self._second_visible:
|
|
320
|
+
return
|
|
321
|
+
maximo = self._max_second()
|
|
322
|
+
if self._size_second > maximo:
|
|
323
|
+
self._size_second = maximo
|
|
324
|
+
self._aplicar_tamanho()
|
|
325
|
+
|
|
326
|
+
def _ao_configurar_divisor(self, event=None) -> None:
|
|
327
|
+
self._desenhar()
|
|
328
|
+
|
|
329
|
+
def _iniciar_arraste(self, event) -> str:
|
|
330
|
+
self._divider.focus_set()
|
|
331
|
+
self._drag_start = (
|
|
332
|
+
event.x_root if self._is_horizontal else event.y_root
|
|
333
|
+
)
|
|
334
|
+
self._drag_size = self._size_second
|
|
335
|
+
return "break"
|
|
336
|
+
|
|
337
|
+
def _arrastar(self, event) -> str:
|
|
338
|
+
if self._drag_start is None or self._drag_size is None:
|
|
339
|
+
return "break"
|
|
340
|
+
posicao = event.x_root if self._is_horizontal else event.y_root
|
|
341
|
+
delta = posicao - self._drag_start
|
|
342
|
+
self._set_size(self._drag_size - delta)
|
|
343
|
+
return "break"
|
|
344
|
+
|
|
345
|
+
def _finalizar_arraste(self, event=None) -> str:
|
|
346
|
+
self._drag_start = None
|
|
347
|
+
self._drag_size = None
|
|
348
|
+
return "break"
|
|
349
|
+
|
|
350
|
+
def _resetar_evento(self, event=None) -> str:
|
|
351
|
+
self.reset()
|
|
352
|
+
return "break"
|
|
353
|
+
|
|
354
|
+
def _tecla(self, direcao: int) -> str:
|
|
355
|
+
passo = 10 if self._is_horizontal else 10
|
|
356
|
+
self._set_size(self._size_second + direcao * passo)
|
|
357
|
+
return "break"
|
|
358
|
+
|
|
359
|
+
def _entrar(self, event=None) -> None:
|
|
360
|
+
self._hover = True
|
|
361
|
+
self._atualizar_cor_divisor()
|
|
362
|
+
|
|
363
|
+
def _sair(self, event=None) -> None:
|
|
364
|
+
self._hover = False
|
|
365
|
+
self._atualizar_cor_divisor()
|
|
366
|
+
|
|
367
|
+
# ------------------------------------------------------------------
|
|
368
|
+
# Aparência
|
|
369
|
+
# ------------------------------------------------------------------
|
|
370
|
+
def _set_appearance_mode(self, mode_string: str) -> None:
|
|
371
|
+
super()._set_appearance_mode(mode_string)
|
|
372
|
+
if hasattr(self, "_divider"):
|
|
373
|
+
self._atualizar_cor_divisor()
|
|
374
|
+
self._desenhar()
|
|
375
|
+
|
|
376
|
+
def _atualizar_cor_divisor(self) -> None:
|
|
377
|
+
if not hasattr(self, "_divider"):
|
|
378
|
+
return
|
|
379
|
+
cor = (
|
|
380
|
+
self._hover_color
|
|
381
|
+
if self._hover and self._hover_color is not None
|
|
382
|
+
else self._divider_color
|
|
383
|
+
)
|
|
384
|
+
try:
|
|
385
|
+
self._divider.configure(
|
|
386
|
+
bg=self._apply_appearance_mode(cor)
|
|
387
|
+
)
|
|
388
|
+
except Exception:
|
|
389
|
+
pass
|
|
390
|
+
|
|
391
|
+
def _desenhar(self) -> None:
|
|
392
|
+
if not hasattr(self, "_divider"):
|
|
393
|
+
return
|
|
394
|
+
self._divider.delete("all")
|
|
395
|
+
if self._grip == "none":
|
|
396
|
+
return
|
|
397
|
+
|
|
398
|
+
largura = self._divider.winfo_width()
|
|
399
|
+
altura = self._divider.winfo_height()
|
|
400
|
+
if largura <= 1 or altura <= 1:
|
|
401
|
+
return
|
|
402
|
+
|
|
403
|
+
cor = self._apply_appearance_mode(self._grip_color)
|
|
404
|
+
if self._is_horizontal:
|
|
405
|
+
x = largura / 2
|
|
406
|
+
y = altura / 2
|
|
407
|
+
if self._grip == "line":
|
|
408
|
+
self._divider.create_line(
|
|
409
|
+
x, y - 12, x, y + 12, fill=cor, width=2
|
|
410
|
+
)
|
|
411
|
+
else:
|
|
412
|
+
for dy in (-8, 0, 8):
|
|
413
|
+
self._divider.create_oval(
|
|
414
|
+
x - 1.5,
|
|
415
|
+
y + dy - 1.5,
|
|
416
|
+
x + 1.5,
|
|
417
|
+
y + dy + 1.5,
|
|
418
|
+
fill=cor,
|
|
419
|
+
outline="",
|
|
420
|
+
)
|
|
421
|
+
else:
|
|
422
|
+
x = largura / 2
|
|
423
|
+
y = altura / 2
|
|
424
|
+
if self._grip == "line":
|
|
425
|
+
self._divider.create_line(
|
|
426
|
+
x - 12, y, x + 12, y, fill=cor, width=2
|
|
427
|
+
)
|
|
428
|
+
else:
|
|
429
|
+
for dx in (-8, 0, 8):
|
|
430
|
+
self._divider.create_oval(
|
|
431
|
+
x + dx - 1.5,
|
|
432
|
+
y - 1.5,
|
|
433
|
+
x + dx + 1.5,
|
|
434
|
+
y + 1.5,
|
|
435
|
+
fill=cor,
|
|
436
|
+
outline="",
|
|
437
|
+
)
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ctk-split-pane
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A resizable split-pane widget for CustomTkinter.
|
|
5
|
+
Author: Mikael Gois
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/MikaelGois/ctk-split-pane
|
|
8
|
+
Project-URL: Repository, https://github.com/MikaelGois/ctk-split-pane
|
|
9
|
+
Project-URL: Issues, https://github.com/MikaelGois/ctk-split-pane/issues
|
|
10
|
+
Keywords: customtkinter,tkinter,widget,split-pane,splitter
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: X11 Applications
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Software Development :: User Interfaces
|
|
22
|
+
Classifier: Topic :: Software Development :: Widget Sets
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: customtkinter>=5.2.0
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# ctk-split-pane
|
|
30
|
+
|
|
31
|
+
A resizable two-pane widget for [CustomTkinter](https://github.com/TomSchimansky/CustomTkinter).
|
|
32
|
+
|
|
33
|
+
It provides a draggable divider with three grip dots, double-click reset,
|
|
34
|
+
minimum pane sizes and Dark/Light appearance support.
|
|
35
|
+
|
|
36
|
+
[Português](https://github.com/MikaelGois/ctk-split-pane/blob/main/README.pt-BR.md) | **English**
|
|
37
|
+
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
┌──────────────────────┬───────────────┐
|
|
42
|
+
│ │ │
|
|
43
|
+
│ First pane ║ Second pane │
|
|
44
|
+
│ │ │
|
|
45
|
+
└──────────────────────┴───────────────┘
|
|
46
|
+
↑
|
|
47
|
+
drag to resize
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install ctk-split-pane
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
import customtkinter as ctk
|
|
60
|
+
from ctk_split_pane import CTkSplitPane
|
|
61
|
+
|
|
62
|
+
ctk.set_appearance_mode("dark")
|
|
63
|
+
|
|
64
|
+
app = ctk.CTk()
|
|
65
|
+
app.geometry("900x600")
|
|
66
|
+
|
|
67
|
+
split = CTkSplitPane(
|
|
68
|
+
app,
|
|
69
|
+
orientation="horizontal", # or "vertical"
|
|
70
|
+
initial=280, # initial size of the second pane
|
|
71
|
+
default=280, # size restored by double-click
|
|
72
|
+
min_first=400, # minimum size of the first pane
|
|
73
|
+
min_second=220, # minimum size of the second pane
|
|
74
|
+
)
|
|
75
|
+
split.pack(fill="both", expand=True, padx=10, pady=10)
|
|
76
|
+
|
|
77
|
+
left = ctk.CTkFrame(split.first)
|
|
78
|
+
left.pack(fill="both", expand=True)
|
|
79
|
+
|
|
80
|
+
right = ctk.CTkFrame(split.second)
|
|
81
|
+
right.pack(fill="both", expand=True)
|
|
82
|
+
|
|
83
|
+
app.mainloop()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The content of each pane must be created inside `split.first` / `split.second`
|
|
87
|
+
(or the aliases `split.pane_a` / `split.pane_b`).
|
|
88
|
+
|
|
89
|
+
## Features
|
|
90
|
+
|
|
91
|
+
- Horizontal and vertical orientation.
|
|
92
|
+
- Draggable divider.
|
|
93
|
+
- Three vertical (or horizontal) grip dots as a visual indicator.
|
|
94
|
+
- Resize cursor.
|
|
95
|
+
- Double-click restores the default size.
|
|
96
|
+
- Minimum size for each pane.
|
|
97
|
+
- The second pane is never smaller than `min_second`.
|
|
98
|
+
- The first pane keeps `min_first`; the second is limited to the available space.
|
|
99
|
+
- Hide/show the second pane while preserving its current size.
|
|
100
|
+
- Colors and theme integrated with CustomTkinter; accepts fixed colors or
|
|
101
|
+
`(light, dark)` tuples.
|
|
102
|
+
- `on_resize` and `on_reset` callbacks.
|
|
103
|
+
- Keyboard navigation on the divider: arrow keys and `Home` (when focused).
|
|
104
|
+
- No dependencies other than `customtkinter`.
|
|
105
|
+
|
|
106
|
+
## API
|
|
107
|
+
|
|
108
|
+
### `CTkSplitPane(master, **options)`
|
|
109
|
+
|
|
110
|
+
| Option | Default | Description |
|
|
111
|
+
|---|---|---|
|
|
112
|
+
| `orientation` | `"horizontal"` | `"horizontal"` or `"vertical"`. |
|
|
113
|
+
| `initial` | `default` | Initial size of the second pane. |
|
|
114
|
+
| `default` | `250` | Size restored by `reset()`/double-click. |
|
|
115
|
+
| `min_first` | `120` | Minimum size of the first pane. |
|
|
116
|
+
| `min_second` | `120` | Minimum size of the second pane. |
|
|
117
|
+
| `divider_width` | `10` | Divider thickness. |
|
|
118
|
+
| `grip` | `"dots"` | `"dots"`, `"line"` or `"none"`. |
|
|
119
|
+
| `divider_color` | `("#d9d9d9", "#3a3a3a")` | Divider color (str or `(light, dark)`). |
|
|
120
|
+
| `grip_color` | `("#8a8a8a", "#9a9a9a")` | Grip color. |
|
|
121
|
+
| `hover_color` | `("#c8c8c8", "#4a4a4a")` | Divider color on hover. |
|
|
122
|
+
| `cursor` | automatic | Divider cursor. |
|
|
123
|
+
| `on_resize` | `None` | Called with the new second-pane size. |
|
|
124
|
+
| `on_reset` | `None` | Called after a reset. |
|
|
125
|
+
| `first_pane_kwargs` | `None` | Extra options for the first pane `CTkFrame`. |
|
|
126
|
+
| `second_pane_kwargs` | `None` | Extra options for the second pane `CTkFrame`. |
|
|
127
|
+
|
|
128
|
+
### Methods
|
|
129
|
+
|
|
130
|
+
| Method | Description |
|
|
131
|
+
|---|---|
|
|
132
|
+
| `set_second_size(size)` | Sets the second-pane size (within limits). |
|
|
133
|
+
| `get_second_size()` | Returns the current second-pane size. |
|
|
134
|
+
| `reset()` | Restores the default size. |
|
|
135
|
+
| `hide_second()` | Hides the second pane and divider. |
|
|
136
|
+
| `show_second()` | Shows the second pane at its previous position. |
|
|
137
|
+
| `toggle_second()` | Toggles hidden/visible. |
|
|
138
|
+
| `set_default_size(size)` | Changes the default size. |
|
|
139
|
+
| `set_min_second(size)` | Changes the second-pane minimum. |
|
|
140
|
+
| `set_min_first(size)` | Changes the first-pane minimum. |
|
|
141
|
+
| `is_second_visible` | Boolean property. |
|
|
142
|
+
| `first` / `second` | Internal frames where content should be created. |
|
|
143
|
+
| `pane_a` / `pane_b` | Aliases for `first` / `second`. |
|
|
144
|
+
|
|
145
|
+
## Theming
|
|
146
|
+
|
|
147
|
+
Colors can be strings or `(light, dark)` tuples:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
CTkSplitPane(
|
|
151
|
+
app,
|
|
152
|
+
divider_color=("#e5e5e5", "#2b2b2b"),
|
|
153
|
+
grip_color=("#808080", "#a0a0a0"),
|
|
154
|
+
hover_color=("#cccccc", "#444444"),
|
|
155
|
+
)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
The widget follows `ctk.set_appearance_mode("light"/"dark")` automatically.
|
|
159
|
+
Default colors are neutral; consumers can pass their own palette.
|
|
160
|
+
|
|
161
|
+
## Development
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
git clone https://github.com/MikaelGois/ctk-split-pane.git
|
|
165
|
+
cd ctk-split-pane
|
|
166
|
+
python -m venv .venv
|
|
167
|
+
.venv\Scripts\activate # Windows
|
|
168
|
+
# source .venv/bin/activate # Linux/macOS
|
|
169
|
+
pip install customtkinter
|
|
170
|
+
python examples/demo.py
|
|
171
|
+
python -m unittest discover -s tests -v
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
On Linux, the graphical tests need a virtual display:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
xvfb-run -a python -m unittest discover -s tests -v
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Release process: see [PUBLISHING.md](PUBLISHING.md) (Portuguese).
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
ctk_split_pane/__init__.py,sha256=IJNCBikY17794raFNDXc7ntVkrGP5aFwtqZfjoz4_kw,127
|
|
2
|
+
ctk_split_pane/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
ctk_split_pane/split_pane.py,sha256=X58AyKMQi9YgDekaz56PYhS8qlbw-apdWd1JE1N8wyk,15986
|
|
4
|
+
ctk_split_pane-0.1.0.dist-info/licenses/LICENSE,sha256=PgIiNkkBd1Ic9XaJFw5Zw5ZnofAr6tslt3T95nubCFc,1068
|
|
5
|
+
ctk_split_pane-0.1.0.dist-info/METADATA,sha256=LxiEP8h740TgAekJCm7HHGkt8cWhzODUPaJ-0ecsmfo,6376
|
|
6
|
+
ctk_split_pane-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
ctk_split_pane-0.1.0.dist-info/top_level.txt,sha256=M4goiUFx6-5y3PuoXZ_tQl25zjVb7X8kRNP_RO8dPpk,15
|
|
8
|
+
ctk_split_pane-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mikael Gois
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ctk_split_pane
|