From e563236fb07628dfec57f7cd887b63f4d87e2067 Mon Sep 17 00:00:00 2001 From: emkael Date: Sun, 7 Jul 2019 19:48:23 +0200 Subject: ScrollableFrame scrollable via mouse wheel --- jfr_playoff/gui/frames/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'jfr_playoff') 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('', self._onFrameConfigure) self.canvas.bind('', self._onCanvasConfigure) + self.bind('', partial(self._setScroll, value=True)) + self.bind('', partial(self._setScroll, value=False)) self.renderContent(frame) + def _setScroll(self, event, value): + if value: + self.bind_all('', self._onVscroll) + self.bind_all('', self._onHscroll) + else: + self.unbind_all('') + self.unbind_all('') + + 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')) -- cgit v1.2.3