Info passed thru 'Event' 
Author Message
 Info passed thru 'Event'

Better late than never...


> > It sounds like you are using top-level functions for your callbacks.
> > Personally, I prefer to use class methods; a separate method for each
> > widget.  A simple example:

> Actually, that's exactly what I do. I was getting confused by the online
> documentation when it came to the 'command' parameter and the 'bind'
> method of certain widgets.

Command ia form of binding in that sense, yes.  But command callbacks (as
you have discovered) aren't passed any event information.  However,
command behaves in certain useful ways.

Take a Button for instance.  If you click and hold on it, it remains
depressed but doesn't activate.  If you move the mouse off the Button, it
raises again; even if you release the mouse button now, the callback will
still not be made.  Only if you click and release in the same button will
this happen.  Commands do all this for you.

Events have much simpler behavior, such as "mouse button 1 down".  Often,
this is sufficient but doesn't provide the polished look and feel.

> So I was surprised that the 'callback' called through 'command' didn't get
> any 'Event' information. Then, I ignored 'command' and used 'bind' which
> gave me the result I expected (Event gets passed, and I can query it for
> anything of interests -- like the label of the checkbutton that invoked
> the callback f() )

If that's what you want to do, you could try something like this.

class CheckbuttonWithInformativeCallback(Tkinter.Checkbutton):
  def __init__(self, master, **cnf):
      self._callback = cnf['command']
    except KeyError:
      self._callback = None

    if (self._callback is not None):
      cnf['command'] = self.DoCallback

    apply(Tkinter.Checkbutton, (self, master), cnf)

  def DoCallback(self):
    apply(self._callback, (self,))

(Code above probably has a bug or two.)

Milton L. Hankins   <><   Software Engineer, Raytheon Systems Company
 John 3:16 || I can't speak for Raytheon Company, but I often try to
  L-I-F-E  || speak for my wife and my cat.  The latter doesn't mind.

Sat, 03 Feb 2001 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Info passed thru 'Event'

2. Expect event loop triggers 'after' events

3. Info on Tcl's channel system (specifically file events) needed

4. Boolean controls don't respond to input when inside an event in the event structure

5. Merging Tcl's event loop with some other event loop

6. Merging Tcl's event loop with other event loops (notifier)

7. I need 'EVENT:Paint'

8. VI's GUI events disturb another VI's work

9. s'ACTIVE vs s'EVENT??

10. S'STABLE = not S'EVENT ?

11. HowTo use 'event gen'

12. tcl event loop + c code 'select'


Powered by phpBB® Forum Software