Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sensitive scrollbar feature #2539

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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