Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion customtkinter/windows/widgets/ctk_scrollable_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self,
self._parent_canvas.configure(width=self._apply_widget_scaling(self._desired_width),
height=self._apply_widget_scaling(self._desired_height))

self.bind("<Configure>", lambda e: self._parent_canvas.configure(scrollregion=self._parent_canvas.bbox("all")))
self.bind("<Configure>", self._update_scroll_region)
self._parent_canvas.bind("<Configure>", self._fit_frame_dimensions_to_canvas)
self.bind_all("<MouseWheel>", self._mouse_wheel_all, add="+")
self.bind_all("<KeyPress-Shift_L>", self._keyboard_shift_press_all, add="+")
Expand Down Expand Up @@ -238,6 +238,23 @@ def _fit_frame_dimensions_to_canvas(self, event):
elif self._orientation == "vertical":
self._parent_canvas.itemconfigure(self._create_window_id, width=self._parent_canvas.winfo_width())

self._check_scroll_necessity()

def _check_scroll_necessity(self):
canvas_height = self._parent_canvas.winfo_height()
content_height = self.winfo_height()

if content_height <= canvas_height:
self._scrollbar.grid_remove()
self._parent_canvas.configure(yscrollcommand=None)
else:
self._scrollbar.grid()
self._parent_canvas.configure(yscrollcommand=self._scrollbar.set)

def _update_scroll_region(self, event=None):
self._parent_canvas.configure(scrollregion=self._parent_canvas.bbox("all"))
self._check_scroll_necessity()

def _set_scroll_increments(self):
if sys.platform.startswith("win"):
self._parent_canvas.configure(xscrollincrement=1, yscrollincrement=1)
Expand Down