0

Hi guys,

I'm new to Python have get done a lot by searching. Now I try to bind a scroll wheel to canvas, but it doesn't do anything. Will someone look at the code what I do wrong?
I tried to keep my snippet clean. Hope It's enough.

class Viewer(tk.Toplevel):
    def __init__(self, master, listBoxValue):
        tk.Toplevel.__init__(self, master)

        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)
        cnv = Canvas(self)
        cnv.grid(row=0, column=0, sticky='nswe')
        vScroll = Scrollbar(self, orient=VERTICAL, command=cnv.yview)
        vScroll.grid(row=0, column=1, sticky='ns')
        cnv.configure(yscrollcommand=vScroll.set)
        frm = Frame(cnv)
        cnv.create_window(0, 0, window=frm, anchor='nw')
        cnv.bind_all('<MouseWheel>', lambda event: self.on_vertical)

    #select data from database
        #loop through rows
            #Label(frm, image=image) # attach image to frame

    cnv.configure(scrollregion=(0, 0, frm.winfo_width(), frm.winfo_height() + 40))

    def on_vertical(self, event):
        print('scroll')
        self.cnv.yview_scroll(-1 * event.delta, 'units')
2
Contributors
1
Reply
10
Views
1 Year
Discussion Span
Last Post by rproffitt
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.