forked from Ignatella/slow-down-or-mandat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrollbarlist.py
More file actions
47 lines (40 loc) · 2.46 KB
/
scrollbarlist.py
File metadata and controls
47 lines (40 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import customtkinter as ctk
import os
class ScrollbarList(ctk.CTkFrame):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.images_list = []
self.grid_rowconfigure(1, weight=1)
self.grid_columnconfigure(0, weight=1)
self.scrollbar_label = ctk.CTkLabel(
self, text="Your images", font=ctk.CTkFont(size=20, weight="bold"))
self.scrollbar_label.grid(
row=0, column=0, padx=20, pady=20, sticky="nswe")
self.canvas = ctk.CTkCanvas(self, width=140, highlightthickness=0)
self.canvas.grid(row=1, column=0, sticky="nswe")
self.canvas.grid_columnconfigure(0, weight=1)
self.scrollbar = ctk.CTkScrollbar(self, command=self.canvas.yview)
self.scrollbar.grid(row=1, column=1, sticky="nswe")
self.inner_frame = ctk.CTkFrame(self.canvas, corner_radius=0)
self.inner_frame.grid_columnconfigure(0, weight=1)
self.canvas_frame = self.canvas.create_window(
(0, 0), window=self.inner_frame, anchor="center")
self.canvas.configure(yscrollcommand=self.scrollbar.set)
self.inner_frame.bind("<Configure>", lambda e: self.canvas.configure(
scrollregion=self.canvas.bbox("all")))
self.canvas.bind("<Configure>", self.resize_frame)
self.canvas.bind_all("<MouseWheel>", self.on_mouse_wheel)
# ctk.CTkLabel(self.inner_frame, text="no images").grid(row=0, column=0, sticky="nswe")
# for i in range(100):
# ctk.CTkButton(self.inner_frame, corner_radius=0, border_spacing=5, text=f"image-name{i}.png",
# fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30")).pack(fill="both")
def add_image(self, setImage, image, res=""):
self.images_list.append(ctk.CTkButton(self.inner_frame, corner_radius=0, border_spacing=5, text=f'{os.path.basename(image)} {res}',
fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"), command=lambda: setImage(image)))
self.images_list[-1].pack(fill="both")
def on_mouse_wheel(self, event):
self.canvas.yview_scroll(-1 * int((event.delta / 120)), "units")
def resize_frame(self, event):
self.canvas.itemconfig(self.canvas_frame, width=event.width)
if event.height > self.inner_frame.winfo_height():
self.canvas.itemconfig(self.canvas_frame, height=event.height)