0

Scroll is working well. but how can i bind mouse wheel with the scroll? i am using ubuntu.

#code.

from tkinter import *
from tkinter import ttk
win = Tk()

wrapper1 = LabelFrame(win)
mycanvas = Canvas(wrapper1).pack(side=LEFT, fill='both', expand='yes')
yscrollbar = ttk.Scrollbar(wrapper1, orient="vertical", command=mycanvas.yview ).pack(side=RIGHT, fill='y')
mycanvas.configure(yscrollcommand=yscrollbar.set)
mycanvas.bind('<Configure>', lambda e: mycanvas.configure(scrollregion = mycanvas.bbox('all')))
myframe = Frame(mycanvas)
mycanvas.create_window((0,0), window=myframe, anchor='nw')

wrapper1.pack(fill="both", expand="yes", padx=10, pady=10)

for i in range(30):
    Button(myframe, text="btn" + str(i)).pack()

win.geometry("500x500")
win.resizable(height=FALSE,width=FALSE)


win.mainloop()
  • 1
    Does this answer your question? [tkinter: binding mousewheel to scrollbar](https://stackoverflow.com/questions/17355902/tkinter-binding-mousewheel-to-scrollbar) – j_4321 Jun 30 '22 at 12:10
  • I saw this answer, tried, but could not – Salamander. Jun 30 '22 at 13:10
  • 1
    What went wrong then? I don't see any attempt to bind scrolling to the mousewheel in your code. Note that you need to do the binding to buttons 4 and 5 (see 3rd bullet point in the accepted answer or the answer by Joe Michail for the question I linked above) – j_4321 Jun 30 '22 at 13:18
  • I have followed the steps of Bryan Oakley,Joe Michail.. bind with "mycanvas",, but no luck. don't understand why it doesn't work :) – Salamander. Jun 30 '22 at 14:31
  • Your code sample does not run. I get `AttributeError: 'NoneType' object has no attribute 'create_window'` because of the line `mycanvas = Canvas(wrapper1).pack(side=LEFT, fill='both', expand='yes')` , see https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name + same issue with the scrollbar. – j_4321 Jun 30 '22 at 14:36
  • So please edit your code sample to fix that, then include your attempt to apply the answers of https://stackoverflow.com/questions/17355902/tkinter-binding-mousewheel-to-scrollbar so that we can see what goes wrong. – j_4321 Jun 30 '22 at 14:38

0 Answers0