diff --git a/customtkinter/windows/widgets/ctk_scrollable_frame.py b/customtkinter/windows/widgets/ctk_scrollable_frame.py index eede0911..0a67ed51 100644 --- a/customtkinter/windows/widgets/ctk_scrollable_frame.py +++ b/customtkinter/windows/widgets/ctk_scrollable_frame.py @@ -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("", lambda e: self._parent_canvas.configure(scrollregion=self._parent_canvas.bbox("all"))) + self.bind("", self._update_scroll_region) self._parent_canvas.bind("", self._fit_frame_dimensions_to_canvas) self.bind_all("", self._mouse_wheel_all, add="+") self.bind_all("", self._keyboard_shift_press_all, add="+") @@ -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)