Adding bindings in Tk [QUESTION]

Tom Jones (tom@cs.su.oz.au)
27 Feb 1995 13:20:48 +1100

Something is not behaving as it ought, and I'm hoping it's not me...

Let me demonstrate my problem / questions with some self contained code:

#######################################
#!/usr/local/bin/python
from Tkinter import *

class Test(Frame):
def mine(self, e):
print "hello friend "

def createWidgets(self):
self.QUIT = Button(self, {'text': 'QUIT', 'command': self.quit})
self.QUIT.pack({'side': 'bottom', 'fill': 'both'})
self.QUIT.bind('<Any-Motion>', self.mine, "+")

def __init__(self, master=None):
Frame.__init__(self, master)
Pack.config(self)
self.createWidgets()

test = Test()

test.mainloop()
#######################################

Notice the binding, 'Any-Motion', which causes a stream of "hello friend"s
when the mouse moves over the Button, and if I select the button it
behaves as normal and executes its command - self.quit.

Now if I change the binding to 'Any-Enter' (or just 'Enter'), which I would
say is the binding used by the Button classes to trap that event so the button
can be highlighted, the "hello friend" works fine, but the button is
no longer highlighted, and indeed doesn't work properly any more.

If I wasn't doing the "+" in the bind, then this would be OK, but I
thought (hoped) that this would add my event to the Button's own, but
doesn't seem to.

Does any-body know anything about this?
I hope so, because I have this really snazzy mouse-sensitive help
system that I'm working on, but I'd like to use the 'Enter' and 'Leave'
events without screwing the classes that already are using them.

PS : I did test the use of "+", adding another binding to an identical
event (ie a line such as self.QUIT.bind('<Any-Motion>', self.my_second_fn, "+"))
and that works fine.

thanks!

tom