diff options
author | emkael <emkael@tlen.pl> | 2019-07-07 19:48:23 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-07-07 19:48:23 +0200 |
commit | e563236fb07628dfec57f7cd887b63f4d87e2067 (patch) | |
tree | 3cbfb697ae763d433bdb6d5a347268afd13eec1c /jfr_playoff/gui/frames/__init__.py | |
parent | adada21ae38d7fbc8f9a6eba1bb1f591a3452480 (diff) |
ScrollableFrame scrollable via mouse wheel
Diffstat (limited to 'jfr_playoff/gui/frames/__init__.py')
-rw-r--r-- | jfr_playoff/gui/frames/__init__.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/jfr_playoff/gui/frames/__init__.py b/jfr_playoff/gui/frames/__init__.py index 9f762bf..89e0155 100644 --- a/jfr_playoff/gui/frames/__init__.py +++ b/jfr_playoff/gui/frames/__init__.py @@ -217,8 +217,28 @@ class ScrollableFrame(tk.Frame): (0,0), window=frame, anchor=tk.N+tk.W) frame.bind('<Configure>', self._onFrameConfigure) self.canvas.bind('<Configure>', self._onCanvasConfigure) + self.bind('<Enter>', partial(self._setScroll, value=True)) + self.bind('<Leave>', partial(self._setScroll, value=False)) self.renderContent(frame) + def _setScroll(self, event, value): + if value: + self.bind_all('<MouseWheel>', self._onVscroll) + self.bind_all('<Shift-MouseWheel>', self._onHscroll) + else: + self.unbind_all('<MouseWheel>') + self.unbind_all('<Shift-MouseWheel>') + + def _onHscroll(self, event): + self._onScroll(tk.X, -1 if event.delta > 0 else 1) + + def _onVscroll(self, event): + self._onScroll(tk.Y, -1 if event.delta > 0 else 1) + + def _onScroll(self, direction, delta): + getattr( + self.canvas, '%sview' % (direction))(tk.SCROLL, delta, tk.UNITS) + def _onFrameConfigure(self, event): self.canvas.configure(scrollregion=self.canvas.bbox('all')) |