mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
add_both_vertical_and_horizontal_scroll in ctk_scrollable_frame.py
This commit is contained in:
parent
e116faf910
commit
6286dc3719
@ -36,7 +36,7 @@ class CTkScrollableFrame(tkinter.Frame, CTkAppearanceModeBaseClass, CTkScalingBa
|
|||||||
label_text: str = "",
|
label_text: str = "",
|
||||||
label_font: Optional[Union[tuple, CTkFont]] = None,
|
label_font: Optional[Union[tuple, CTkFont]] = None,
|
||||||
label_anchor: str = "center",
|
label_anchor: str = "center",
|
||||||
orientation: Literal["vertical", "horizontal"] = "vertical"):
|
orientation: Literal["vertical", "horizontal", "both"] = "vertical"):
|
||||||
|
|
||||||
self._orientation = orientation
|
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,
|
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)
|
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)
|
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_text = label_text
|
||||||
self._label = CTkLabel(self._parent_frame, text=label_text, anchor=label_anchor, font=label_font,
|
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._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)
|
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 != "":
|
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)
|
self._label.grid(row=0, column=0, columnspan=2, sticky="ew", padx=border_spacing, pady=border_spacing)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user