0

i want to be able to scroll down my list in tkinter with my mousewheel. how can i achieve that?

i have already tried to define a mousewheel function and binding the mousewheel to the canvasframe. But it didnt work.

from tkinter import *
def update_scrollregion(event):
    photoCanvas.configure(scrollregion=photoCanvas.bbox("all"))

root = Tk()
root.geometry("1700x900")   

photoFrame = Frame(root, width=250, height=190, bg="#EBEBEB")
photoFrame.grid()
photoFrame.rowconfigure(0, weight=1) 
photoFrame.columnconfigure(0, weight=1) 

photoCanvas = Canvas(photoFrame, bg="#EBEBEB")
photoCanvas.grid(row=0, column=0, sticky="nsew")

canvasFrame = Frame(photoCanvas, bg="#EBEBEB")
photoCanvas.create_window(0, 0, window=canvasFrame, anchor='nw')

i = 1
while i < 77:
  Label(canvasFrame,text="example",padx=15).grid(row=i,column=1,sticky="W")
  i += 1

photoScroll = Scrollbar(photoFrame, orient=VERTICAL)
photoScroll.config(command=photoCanvas.yview)
photoCanvas.config(yscrollcommand=photoScroll.set)
photoScroll.grid(row=0, column=1, sticky="ns")

canvasFrame.bind("<Configure>", update_scrollregion)

root.mainloop()

0 Answers0