1

I'm making a short program where I extract data from a csv file and order them in a Canvas window placed inside the main root window. Of course I put a scrollbar because the list of pretty long.

    frameList = Frame(root, width=300, height=300)
    frameList.place(x=0, y=315)
    canvasWindow = Canvas(frameList, bg='#FFFFFF', width=950, height=400, scrollregion=(0, 0, 150, 60000))
    vbar = Scrollbar(frameList, orient=VERTICAL)
    vbar.pack(side=RIGHT, fill=Y)
    vbar.config(command=canvasWindow.yview)
    canvasWindow.config(yscrollcommand=vbar.set)
    canvasWindow.bind("<MouseWheel>", lambda event: canvasWindow.yview_scroll(int(-1*(event.delta/120)), "units"))
    canvasWindow.bind("<Enter>", lambda event: canvasWindow.yview_scroll(int(-1*(event.delta/120)), "units"))
    canvasWindow.pack(side=LEFT, expand=True, fill=BOTH)

I have no problem scrolling it but when the mouse is over labels or buttons that are inside the "CanvasWindow", it doesn't scroll it. Is there a way to include these labels/buttons to the scrolling area?

Thanks a lot for your help

Laurent
  • 188
  • 2
  • 13
  • Check out this link. Might give you want you need: https://stackoverflow.com/questions/17355902/python-tkinter-binding-mousewheel-to-scrollbar – Michael Platt Apr 11 '19 at 13:30
  • Good point. Actually I forgot to mention that I have 2 canvas in the same root window with a scrollbar for both! I already tried the "bind_all" but of course, both canvas move at the same time. Maybe not the best thing to do. I guess if no solution, I will have to separate the canvas in 2 separate windows. – Laurent Apr 11 '19 at 14:36
  • 1
    Did you see the second answer with 9 upvotes on it? It's a solution that targets specific components and might fix your problem for having two canvases that scroll. You also might be able to use a built in scrollable object that you could bind directly to but I'm not familiar enough with the libraries to point out what that might be. Either way, check out the solution that has binding on `` and ``. Seems like it's a viable solution – Michael Platt Apr 11 '19 at 14:44
  • Wow, excellent. It worked. And first success in this forum. I should check more often 2nd answers. Thanks a million – Laurent Apr 11 '19 at 15:26
  • 1
    Glad it work. Going to have someone mark this as a duplicate so it links appropriately just FYI. Happy coding – Michael Platt Apr 11 '19 at 17:58
  • Just did. Tx again – Laurent Apr 11 '19 at 22:36

0 Answers0