Reputation: 951
I currently have a GUI that uses the Text widget, and I realize mouse wheel can be used to scroll up and down the Text widget.
However, I already have a scroll bar for that task, and I am planning to use mouse wheel for other tasks. So how do you unbind this event from Text widget?
Example code:
from Tkinter import *
def onclick():
pass
root = Tk()
text = Text(root)
text.insert(INSERT, "Hello.....")
for _ in range(1000):
text.insert(END, "Bye Bye.....")
text.pack()
text.tag_add("here", "1.0", "1.4")
text.tag_add("start", "1.8", "1.13")
text.tag_config("here", background="yellow", foreground="blue")
text.tag_config("start", background="black", foreground="green")
root.mainloop()
Upvotes: 4
Views: 2009
Reputation: 3964
return 'break'
in the callback will override the default behavior. Just bind the <MouseWheel>
event to the text widget:
def scrollwheel(event):
return 'break'
text.bind('<MouseWheel>', scrollwheel)
Refer to: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm
Upvotes: 4