From b25249cb29289a45021c58d3b534f311fa761d22 Mon Sep 17 00:00:00 2001 From: vincent Date: Wed, 22 Aug 2018 15:01:03 +0200 Subject: [PATCH] add bind mouse wheell --- chaineTV.py | 71 +++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/chaineTV.py b/chaineTV.py index d8b217a..6a473a1 100644 --- a/chaineTV.py +++ b/chaineTV.py @@ -32,39 +32,46 @@ class LabelImage(Label): class ScrollableCanvas(Frame): - def __init__(self, parent, *args, **kw): - Frame.__init__(self, parent, *args, **kw) - - canvas=Canvas(self,width=300,height=300,scrollregion=(0,0,500,500)) - - vbar=Scrollbar(self,orient=VERTICAL) - vbar.pack(side=RIGHT, fill=Y) - vbar.config(command=canvas.yview) - - canvas.config(width=200,height=200) - canvas.config(yscrollcommand=vbar.set) - canvas.pack(side=LEFT,expand=True,fill=BOTH) - - # create a frame inside the canvas which will be scrolled with it - self.interior = interior = Frame(canvas) - interior_id = canvas.create_window(0, 0, window=interior, anchor=NW ) - # track changes to the canvas and frame width and sync them, - # also updating the scrollbar - def _configure_interior(event): - # update the scrollbars to match the size of the inner frame - size = (interior.winfo_reqwidth(), interior.winfo_reqheight()) - canvas.config(scrollregion="0 0 %s %s" % size) - if interior.winfo_reqwidth() != canvas.winfo_width(): - # update the canvas's width to fit the inner frame - canvas.config(width=interior.winfo_reqwidth()) - interior.bind('', _configure_interior) - - def _configure_canvas(event): - if interior.winfo_reqwidth() != canvas.winfo_width(): - # update the inner frame's width to fill the canvas - canvas.itemconfigure(interior_id, width=canvas.winfo_width()) - canvas.bind('', _configure_canvas) + def __init__(self, parent, *args, **kw): + Frame.__init__(self, parent, *args, **kw) + + canvas=Canvas(self,width=300,height=300,scrollregion=(0,0,500,500)) + vbar=Scrollbar(self,orient=VERTICAL) + vbar.pack(side=RIGHT, fill=Y) + vbar.config(command=canvas.yview) + + canvas.config(width=200,height=200) + canvas.config(yscrollcommand=vbar.set) + canvas.pack(side=LEFT,expand=True,fill=BOTH) + + # create a frame inside the canvas which will be scrolled with it + self.interior = interior = Frame(canvas) + interior_id = canvas.create_window(0, 0, window=interior, anchor=NW ) + # track changes to the canvas and frame width and sync them, + # also updating the scrollbar + def _configure_interior(event): + # update the scrollbars to match the size of the inner frame + size = (interior.winfo_reqwidth(), interior.winfo_reqheight()) + canvas.config(scrollregion="0 0 %s %s" % size) + canvas.yview_moveto(1) + if interior.winfo_reqwidth() != canvas.winfo_width(): + # update the canvas's width to fit the inner frame + canvas.config(width=interior.winfo_reqwidth()) + interior.bind('', _configure_interior) + + def _configure_canvas(event): + if interior.winfo_reqwidth() != canvas.winfo_width(): + # update the inner frame's width to fill the canvas + canvas.itemconfigure(interior_id, width=canvas.winfo_width()) + canvas.bind('', _configure_canvas) + + def _MouseWhell(event): + canvas.yview_scroll(-1*(event.delta/120), "units") + self.bind_all("",_MouseWhell) + + + class emmisionGUI(Frame): def __init__(self,parent,**kwarg): Frame.__init__(self,parent)