How do i stop an event from being processed or switch what function is called for it?
Revised Code:
from Tkinter import *
class GUI:
def __init__(self,root):
Window = Frame(root)
self.DrawArea = Canvas(Window)
self.DrawArea.pack()
Window.pack()
self.DrawArea.bind("<Button 1>",self.starttracking)
def updatetracking(self,event):
print event.x,event.y
def finishtracking(self,event):
self.DrawArea.bind("<Button 1>",self.starttracking)
self.DrawArea.unbind("<Motion>")
def starttracking(self,event):
print event.x,event.y
self.DrawArea.bind("<Motion>",self.updatetracking)
self.DrawArea.bind("<Button 1>",self.finishtracking)
if __name__ == '__main__':
root = Tk()
App = GUI(root)
root.mainloop()
You can simply just call
bind()again with the new function for the event. Since you are not making use of the third parameter,add, inbind()this will just overwrite whatever is already there. By default this parameter is''but it also accepts"+", which will add a callback to the callbacks already triggered by that event.If you start using that optional argument however you will need to use the
unbind()function to remove individual callbacks. When you callbind()afuncidis returned. You can pass thisfuncidas the second parameter tounbind().Example: