From 6286dc37195de83d6077461183fcb84b0fdfffe9 Mon Sep 17 00:00:00 2001 From: esaenzzu Date: Mon, 26 Jun 2023 13:28:33 -0600 Subject: [PATCH] add_both_vertical_and_horizontal_scroll in ctk_scrollable_frame.py --- .../windows/widgets/ctk_scrollable_frame.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/customtkinter/windows/widgets/ctk_scrollable_frame.py b/customtkinter/windows/widgets/ctk_scrollable_frame.py index 687f4ad..b802d67 100644 --- a/customtkinter/windows/widgets/ctk_scrollable_frame.py +++ b/customtkinter/windows/widgets/ctk_scrollable_frame.py @@ -36,7 +36,7 @@ class CTkScrollableFrame(tkinter.Frame, CTkAppearanceModeBaseClass, CTkScalingBa label_text: str = "", label_font: Optional[Union[tuple, CTkFont]] = None, label_anchor: str = "center", - orientation: Literal["vertical", "horizontal"] = "vertical"): + orientation: Literal["vertical", "horizontal", "both"] = "vertical"): self._orientation = orientation @@ -57,6 +57,16 @@ class CTkScrollableFrame(tkinter.Frame, CTkAppearanceModeBaseClass, CTkScalingBa self._scrollbar = CTkScrollbar(master=self._parent_frame, orientation="vertical", command=self._parent_canvas.yview, fg_color=scrollbar_fg_color, button_color=scrollbar_button_color, button_hover_color=scrollbar_button_hover_color) self._parent_canvas.configure(yscrollcommand=self._scrollbar.set) + elif self._orientation == "both": + self._scrollbar_y = CTkScrollbar(master=self._parent_frame, orientation="vertical", + command=self._parent_canvas.yview, + fg_color=scrollbar_fg_color, button_color=scrollbar_button_color, + button_hover_color=scrollbar_button_hover_color) + self._scrollbar_x = CTkScrollbar(master=self._parent_frame, orientation="horizontal", + command=self._parent_canvas.xview, + fg_color=scrollbar_fg_color, button_color=scrollbar_button_color, + button_hover_color=scrollbar_button_hover_color) + self._parent_canvas.configure(yscrollcommand=self._scrollbar_y.set, xscrollcommand=self._scrollbar_x.set) self._label_text = label_text self._label = CTkLabel(self._parent_frame, text=label_text, anchor=label_anchor, font=label_font, @@ -115,6 +125,18 @@ class CTkScrollableFrame(tkinter.Frame, CTkAppearanceModeBaseClass, CTkScalingBa self._parent_canvas.grid(row=1, column=0, sticky="nsew", padx=(border_spacing, 0), pady=border_spacing) self._scrollbar.grid(row=1, column=1, sticky="nsew", pady=border_spacing) + if self._label_text is not None and self._label_text != "": + self._label.grid(row=0, column=0, columnspan=2, sticky="ew", padx=border_spacing, pady=border_spacing) + else: + self._label.grid_forget() + elif self._orientation == "both": + self._parent_frame.grid_columnconfigure(0, weight=1) + self._parent_frame.grid_rowconfigure(1, weight=1) + + self._parent_canvas.grid(row=1, column=0, sticky="nsew", padx=(border_spacing, 0), pady=border_spacing) + self._scrollbar_y.grid(row=1, column=1, sticky="nsew", pady=border_spacing) + self._scrollbar_x.grid(row=2, column=0, sticky="nsew", padx=border_spacing) + if self._label_text is not None and self._label_text != "": self._label.grid(row=0, column=0, columnspan=2, sticky="ew", padx=border_spacing, pady=border_spacing) else: