On 18 Apr 2005 13:48:50 -0700, codecraig <[EMAIL PROTECTED]> wrote:

Hi,
  When I do something like.

s = Scale(master)
s.bind("<ENTER>", callback)

def callback(self, event):
    print event.type

I see "7" printed out.  Where are these constants defined for various
event types?  Basically i want to do something like...

def callback(self, event):
    if event.type == ENTER:
        print "You entered"

The usual way is to bind different callbacks on different events. So you won't have to test the event type in your callback, since the callback itself will already have been selected from the event type. If you insist in doing it the way you mention, you can always do:


ENTER_EVENT = 1 KEYPRESS_EVENT = 2 # ...

def myCallback(evtType, evt):
  if evtType == ENTER_EVENT:
    # some action...
  elif evtType == KEYPRESS_EVENT:
    # some other action...
  # ...

myWidget.bind('<Enter>', lambda evt: myCallback(ENTER_EVENT, evt))
myWidget.bind('<KeyPress>', lambda evt: myCallback(KEYPRESS_EVENT, evt))


I can't really see what it will be good for however...

HTH
--
python -c 'print "".join([chr(154 - ord(c)) for c in 
"U(17zX(%,5.z^5(17l8(%,5.Z*(93-965$l7+-"])'
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to